print numbers in Enginering Notation
Afficher commentaires plus anciens
Hi everyone,
I need to print out in a txt file a list of numbers, one for each row, with this format:
i.dddddddddddddde+000 hence 1digit before decimal separator, 14 after that and 3 for the exponent.
Could anyone help me?
Thanks,
Stefano
2 commentaires
Harry Coules
le 13 Fév 2014
Modifié(e) : Harry Coules
le 13 Fév 2014
If your list of numbers is a vector A, for example:
>> A = [pi;20*pi;300*pi;4000*pi;50000*pi]
A =
1.0e+05 *
0.0000
0.0006
0.0094
0.1257
1.5708
The following code will write a text file in the current directory in an output format similar to that which you specified, but with only 2 digits for the exponent:
fileID = fopen('filename.txt','w','n','UTF-8');
formatSpec = '%1.14e\n';
fprintf(fileID,formatSpec,A);
fclose(fileID);
I don't know if there's a 'clean' way to do three digits for the exponent... Does anyone else know?
Regards, Harry
dpb
le 13 Fév 2014
Only if the actual field exponent is 3-digit in length will the C i/o formatting library display the third decimal. AFAIK this is C Standard behavior in that there's no formatting string option to specify the width of the exponent field.
Réponse acceptée
Plus de réponses (1)
Stefano
le 13 Fév 2014
0 votes
Catégories
En savoir plus sur Low-Level File I/O dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!