Azzera filtri
Azzera filtri

Why is sscanf skipping 2 columns on second line?

1 visualizzazione (ultimi 30 giorni)
Mak
Mak il 31 Mag 2017
Modificato: per isakson il 31 Mag 2017
Hi!
I have a text file that has four numeric values on every other line and a date on every other. Sscanf auotmatically skips the date lines, just as I want it to. Howver, when it starts reading the numeric lines, on the second line it only grabs values from the first two columns(four exist altogether). All the other lines are treated correctly. What might be going on? The source file in question is attached to this message.
THanks a lot in advance!
fid2=fopen('allMeasurements.txt','at');
R=0;
D= [9 11 12];
for i = D;
s1=num2str(i);%Next lines creat filename
if i<10;
s0='0';
s1=strcat(s0,s1);
end
s0='000';
s=strcat(s0,s1,'.txt');
sd='data';
s=strcat(sd,s);
fid=fopen(s, 'rt');
while fgetl(fid)~=-1;
R=R+1;
A = sscanf(tline,'%f', [1,4]);%The 4 columns are stored in A
fprintf(fid2,'%f %f\n',B);
end
fclose(fid);
end
fclose(fid2);
  3 Commenti
Mak
Mak il 31 Mag 2017
Hi Guillaume and thanks for the tips on naming. I should have left the last line, before "end", out. But the line that starts: A =... That line produces a 1x4 matrix on each iteration, EXCEPT when it's on the second numeric line of the file(which I have attached). What I want to know is why it treats the second numeric line different to all the rest? They all seem the same.
per isakson
per isakson il 31 Mag 2017
Modificato: per isakson il 31 Mag 2017
Remove the extra dot on line 4
and try
fid = fopen('data00009.txt');
cac = textscan( fid, '%*s\n%f%f%f%f', 'Delimiter','\t', 'CollectOutput',true );
fclose( fid );
>> cac
cac =
[60x4 double]
>> version
ans =
9.0.0.341360 (R2016a)

Accedi per commentare.

Risposte (0)

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by