MATLAB: ??? Error using ==> fprintf Invalid file identifier. Use fopen to generate a valid file identifier. i’m new to matlab HELP ME… using macbook (windows 10) R2010a

data analysis

fprintf(fileID,'%-6s %-6.2s %-12.8s %-12.8s %-12.8s %-12.8s %-12.5s %-12.19s\t %-12.19s\t %-12.18s\t %-12.18s\r\t %-12.19s\t\t %-12.19s\t %-12.19s\t %-12.19s\r\t %-12.19s\t %-12.19s\t %-12.19s\t %-12.19s\r %-12.19s\t %-12.19s\t %-12.19s\t %-12.19s\r %-12.19s\t %-12.19s\t %-12.19s\t %-12.19s\r %-12.19s\t %-12.19s\t %-12.19s\t %-12.19s\r %-12.19s\t %-12.19s\t %-12.19s\t %-12.19s\r %-12.19s\r\n',sat,year,month,day,hour,minute,seconds,ao,a1,a2,ID,Cs,dan,Motoe,Cu,e,Cuc,roa,toe,Cic,omega,Cis,I,Crc,w,omegadt,Idot,m2,GPweek,m2Pcode,satelliteaccuracy,health,Tgd,IC,tym,spare);

Best Answer

The fopen() of the file failed, but you did not check for failure of the fopen(). You should be using
filename = 'WhateverFile.txt';
[fileID, msg] = fopen(filename, 'wt');
if fileID < 0
error('Failed to open file "%s" for writing, because "%s"', filename, msg);
end