Why is sscanf skipping 2 columns on second line?
4 ビュー (過去 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

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 で Data Import and Export についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!