PDA

View Full Version : [Matlab] leggere file di testo malformato


Erotavlas_turbo
16-02-2010, 15:11
Salve,

ho un file di testo "malformato": è simile a un file .CSV ma Matlab non riesce a leggerlo in modo automatico.
Le ho provate tutte importdata, fopen, textscan etc. ma non sono riuscito a leggere il file...

parte del file da leggere

Forward
Packet,Sequence,Time stamp,Delta (ms),Jitter (ms),Skew(ms),IP BW (kbps),Marker,Status
976,61063,0,0.00,0.00,0.00,10.18,,[ Ok ],02/15/2010 14:58:29.639,1286
977,61064,0,0.26,0.02,-0.26,21.04,,[ Ok ],02/15/2010 14:58:29.639,1372
978,61065,0,0.23,0.03,-0.49,26.94,SET,Incorrect timestamp,02/15/2010 14:58:29.639,752
1004,61066,249000,212.21,159.68,2553.96,32.44,SET,[ Ok ],02/15/2010 14:58:29.852,701



codice matlab


fid = fopen('h263w.txt','r');

InputText=textscan(fid,'%s',2,'delimiter','\n'); % Read strings delimited by a carriage return

format = '%f %f %f %f %f %f %f %s %s %f %f';

i=1; % Initialize block index
while (i ~=10) % For each block...

A = textscan(fid, format, 'delimiter',',')
for j=1:7
data(i,j) = A(1,j);
end


i=i+1;
end
fclose(fid);



vorrei ottenere una matrice Nx7 dove N è il numero di righe del file che contiene i valori delle prime 7 colonne.
Non so come fare...grazie