Why is sscanf skipping 2 columns on second line?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
per isakson
2017-5-31
编辑:per isakson
2017-5-31
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)
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!