Use fprintf with fgetl
Show older comments
Hi, I have a text file. I use the fgetl to read all the lines from a text file (screenshot). filename is the path where is the text file. Where i find lines with abb_sat ("PE02") in the begginning of the line, I want to substitue the values in the original file with x_sp3, y_sp3, z_sp3 and dc_sp3 (fprintf inside the while). With this script I can sobstitue these values (x_sp3, y_sp3, z_sp3, dc_sp3) in the next lines and not in that one where I find "PE02". How can I use fprintf to sobsitute these values in the correct lines?
abb_sat = "PE02";
filename = strcat('C:\multiGNSS_v3\mgnssPre\ephConv\',out_sp3_abb,'\',num2str(YR+2000),'\',out_sp3_abb,num2str(WN),num2str(DoW),est);
FID = fopen ( filename , 'r+');
line = fgetl(FID);
x_sp3 = -10000.666666;
y_sp3 = -10.666666;
z_sp3 = -1000.666666;
dc_sp3 = -0.666666;
while ischar(line)
if ~isempty(strfind(line, abb_sat ))
fprintf(FID,'%.5s %13.6f %13.6f %13.6f %13.6f\n', abb_sat, x_sp3, y_sp3, z_sp3, dc_sp3);
end
line = fgetl(FID);
end
fclose(FID);
Accepted Answer
More Answers (0)
Categories
Find more on Standard File Formats in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!