fprintf within a for / if environment with crazy behaviour
Show older comments
Using fprintf in a for / if environment (fileID = correct.XP0000020_0026.dat):
if ProfilKonst == 'X'
for i=1:length(x)
if x(i) == koordinate(1)
fprintf(fileID,'%.2f %.2f %.2f\n',[x(i) y(i) z(i)]);
end
end
end
the file 'correct.XP0000020_0026.dat' is empty, and the output on the console is:
correct.XP0000020_0026.datcorrect.XP0000020_0026.datcorrect.XP0000020_0026.datcorrect.XP0000020_0026.dat..........and so on
But when I use
fprintf('%.2f %.2f %.2f\n',[x(i) y(i) z(i)]);
everything is fine.
The file is opened with fopen(fileID,'wt'). I also tried to move fprintf in a function, but with the same result...
What is wrong? Thanks a lot.
Accepted Answer
More Answers (0)
Categories
Find more on Low-Level File I/O 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!