Why is sscanf skipping 2 columns on second line?
1 view (last 30 days)
Show older comments
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 Comments
per isakson
on 31 May 2017
Edited: per isakson
on 31 May 2017
Remove the extra dot on line 4
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/184641/image.png)
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)
Answers (0)
See Also
Categories
Find more on Text Data Preparation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!