In the following code:
a={[0.111 0.220545];
[0.0000001 0.00023]};
b=cellfun(@(x) num2str(x,3),a,'UniformOutput',false);
I would expect that num2str would limit the significant decimal
elements into 3. But thats not the case. It works for the first row
but not the second. Why?
Thanks in advance
It looks like that the dysfunctional element in the above code is
solely num2str and not the cellfun function.
hmm, as far as I can see the strings look fine (R2008a): I get
b =
'0.111 0.221'
'1e-007 0.00023'
and the second row shows (a maximum of) three significant digits (you gave
one and two sig. digits, and they are printed). Slightly different example
(but working as well)
a={[0.111 0.220545];
[0.0000001234 0.0002345]};
b=cellfun(@(x) num2str(x,3),a,'UniformOutput',false);
b =
'0.111 0.221'
'1.23e-007 0.000235'
Titus
Looks about right to me. Recall that leading zeros in a number are
not considered to be "significant decimal places" unless you know
the potential range of values is such that it would have been possible
for the higher order digits to have been non-zero.
You may wish to use num2str(x,'%.2e ')
Notice the space after the e and before the terminal apostrophe.
--
Q = quotation(rand);
if isempty(Q); error('Quotation server filesystem problems')
else sprintf('%s',Q), end
WAD(esigned)&D(ocumented)...
num2str()'s second argument controls max number of _significant_ digits
If otoh you want only n number of decimal digits, use sprintf() directly.
--
Ok guys, sorry. Now I get it that it was my mistake.