How do I force the output format of arrayfun() to be "short"?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Akzeptierte Antwort
Adam
am 20 Jan. 2017
Bearbeitet: Adam
am 20 Jan. 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.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Characters and Strings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!