MATLAB: Need help with this error using fscanf

errorfscanfhelploopsyntax error

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]);

Best Answer

The size parameter for fscanf can be a scalar, or it can be a vector of values representing an array dimensions. It cannot be used to tell MATLAB to only write to every second output column, and it cannot be used to tell MATLAB to skip scanning input columns. It also cannot be used to tell MATLAB to go back and re-read a different part of the same line.
If you had reason to only read in every second value, then you can use
fscanf(fid, '%g %*s', [1 inf]) %reads odd-numbered columns, discards even-numbered
fscanf(fid, '%*s %g', [1 inf]) %reads even-numbered columns, discards odd-numbered
If you need odd and even in separate variables, then
xy = fscanf(fid, '%g %g', [2 inf]);
x = xy(1,:);
y = xy(2,:);