fprintf and fopen changing the data I'm trying to write
Mostrar comentarios más antiguos
I'm trying to save the result of calculations as an ASCII using fopen and fprintf, but my data becomes corrupted. Snippet below, where the variables are vectors calculated above inside a for loop:
fid01=fopen('Specific_Momentum_and_KE.txt', 'a+');
fprintf(fid01, '%.4f, %.4f, %.4f, %.4f\r\n',tstep, xfland, mag_land_vel, mag_land_KE);
fclose(fid01);
end
I'm getting seemingly random strings of integers in my file, and the numbers which are supposed to be there are wrong--they don't match the output from my Matlab script. Example from the ASCII:
48.0000, 48.0000, 48.0000, 48.0000
0.5053, 0.5862, 0.5963, 0.5923
0.5722, 0.6441, 0.6507, 0.5837
0.6534, 0.6464, 0.6737, 0.6606
0.6153, 0.6864, 0.6746, 0.6344
0.6978, 0.7149, 0.7490, 0.6757
Where the heck did those 48's come from?? Also, the second column should be
0.5052
0.5862
0.5962
0.5922
0.5721
but it's like Matlab is changing my data! Very bad deal. Please help.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!