Borrar filtros
Borrar filtros

How do I force the output format of arrayfun() to be "short"?

6 visualizaciones (últimos 30 días)
Gab3
Gab3 el 20 de En. de 2017
Editada: Adam el 20 de En. de 2017
How do I force the output format of arrayfun() to be "short"?
The code and results to illustrate my issue:
format; %this is the default matlab output format I think
axlim = [ 0.1 50; 0.1 7; 50 2000]
format shortG;
axlim
lbl1 = arrayfun(@(lo,hi) sprintf('(%d,%d)', lo, hi), axlim(:,1), axlim(:,2), 'UniformOutput', 0)
axlim =
1.0e+03 *
0.0001 0.0500
0.0001 0.0070
0.0500 2.0000
axlim =
0.1 50
0.1 7
50 2000
lbl1 =
'(1.000000e-01,50)'
'(1.000000e-01,7)'
'(50,2000)'
The result that I need is:
lbl1 =
'(0.1 ,50)'
'(0.1,7)'
'(50,2000)'
Kind of related to this https://www.mathworks.com/matlabcentral/newsreader/view_thread/156758 but I need an extra step of forcing the output format to be simple and short

Respuesta aceptada

Adam
Adam el 20 de En. de 2017
Editada: Adam el 20 de En. de 2017
lbl1 = arrayfun(@(lo,hi) sprintf('(%g,%g)', lo, hi), axlim(:,1), axlim(:,2), 'UniformOutput', 0)
The help...
doc sprintf
contains a section on the formatSpec and the different conversions you can use. %g is the compact version.
It is totally independent of the format you are using - it is entirely dictated by what is in your sprintf since it is a string that you are outputting.

Más respuestas (0)

Categorías

Más información sobre String Parsing 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!

Translated by