Need help with this error using fscanf
显示 更早的评论
I am creating a loop to read a rather large multi column txt file and change the 2 digit date to 4 digit and my scan function is returning an error in line 6 the first line fscanf is used I am sure its in my syntax used there. Any help is much appreciated!!!
fid=fopen('test.txt', 'r')
while ~feof(fid)
tline=fgetl(fid);
Year=fscanf(fid,'%g',[1 1:2:inf]);
Month=fscanf(fid,'%g',[1 2:2:inf]);
Lowtemp=fscanf(fid,'%g',[1 2:2:inf]);
Hightemp=fscanf(fid,'%g',[1 2:2:inf]);
Precip=fscanf(fid,'%g',[1 2:2:inf]);
Year=Year + 1900
end
fileID = fopen('newtxt.txt','w');
fprintf(fileID, 'Year Month LowTemp HighTemp Precip\n');
fprintf(fileID,'%g %g %g %g %g\n',Year,Month,Lowtemp,Hightemp,Precip);
fclose(fileID);
_____________
>> temphw
fid =
9
Maximum variable size allowed by the program is exceeded.
Error in temphw (line 6)
Year=scanf(fid,'%g',[1 1:2:inf]);
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!