Matlab - print number in scientific notation that starts at zero, type 0.5000E + 01

 
Vista:

print number in scientific notation that starts at zero, type 0.5000E + 01

Publicado por Alonso Aguilar (2 intervenciones) el 24/04/2019 02:47:14
I need to print a document with the numbers in scientific notation, but always start at zero
something like: 0.5000E + 01 0.5000E + 01 -.1500E + 02
I use the instruction: fprintf (fileID, '% 0.4E% 0.4E% 0.4E \ n', str2double (M (i, 5)), str2double (M (i, 6)), str2double (M (i, 7) ))
but what I get is: 5.0000E + 00 5.0000E + 00 -5.0000E + 00
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 918
Bronce
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

print number in scientific notation that starts at zero, type 0.5000E + 01

Publicado por Daniel (354 intervenciones) el 24/04/2019 21:32:41
The problem is very easy if you assume that it is necessary to create a function which format the numbers. As example you can use the following code:

1
2
3
4
str = sprintf('0.%0.6e', pi);
str(4) = '';
pos = strfind(str, 'e');
str = [str(1:pos), sprintf('%+2d', str2double(str(pos+1:end)) + 1)];

Analytics Lane
Matlab en Analytics Lane
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

print number in scientific notation that starts at zero, type 0.5000E + 01

Publicado por Alonso Aguilar (2 intervenciones) el 24/04/2019 23:50:59
Can you do that without losing the number properties?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 918
Bronce
Ha mantenido su posición en Matlab (en relación al último mes)
Gráfica de Matlab

print number in scientific notation that starts at zero, type 0.5000E + 01

Publicado por Daniel (354 intervenciones) el 25/04/2019 09:40:25
I assume you are talking about the sing of the value where it is negative. In this case you need to use a different version.

1
2
3
4
5
6
7
8
9
10
if pi >= 0
    str = sprintf('0.%0.6e', pi);
    str(4) = '';
else
    str = sprintf('-0.%0.6e', pi);
    str(5) = '';
end
 
pos = strfind(str, 'e');
str = [str(1:pos), sprintf('%+2d', str2double(str(pos+1:end)) + 1)];
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar