How do I force the output format of arrayfun() to be "short"?
6 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Adam
on 20 Jan 2017
Edited: Adam
on 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 Comments
More Answers (0)
See Also
Categories
Find more on String Parsing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!