Make num2str in engineering format
66 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Yoav Romach
el 6 de Mzo. de 2014
Respondida: Steven Lord
el 22 de Nov. de 2021
Hey, I'm writing this code:
disp(['Cutoff frequency: ',num2str(wcutoff,'%e')]);
and this displays the frequency in an normal exponential format, but I want it to be in eng format. This means that instead of:
5.2e10
I want it to show:
52.0e9
Is that possible? A possible workaround could be to use "format shortEng" and than separate the display code into 2 lines, but than I need to find a way that it'll display it in one output line or something like that...
0 comentarios
Respuesta aceptada
Más respuestas (3)
Steven Lord
el 22 de Nov. de 2021
If you're using release R2021a or later I would use formattedDisplayText instead of evalc.
wcutoff = 5.2e10;
t = formattedDisplayText(wcutoff, 'NumericFormat', 'shortEng')
0 comentarios
Harry Dymond
el 16 de Jul. de 2019
For the benifit of those stumbling across this old thread in search of answers: my FEX submission num2eng will do what the OP is asking for.
0 comentarios
Jos (10584)
el 7 de Mzo. de 2014
A similar effect can be obtained by manipulating the string rather than the numbers
X = 52346574 ;
s1 = sprintf('%.2e',X)
v = sscanf(s1,'%d.%de%d')
s2 = sprintf('%d%.1fe%02d',v(1), v(2)/10, v(3)-1)
disp(['Cutoff frequency: ', s2]);
Which can be made into a function handle:
Val2EngString = @(X) sprintf('%d%.1fe%02d',[1 .1 1] .* sscanf(sprintf('%.2e',X),'%d.%de%d').' - [0 0 1])
disp(Val2EngString(2340000000))
1 comentario
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!