Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: num2sr strange behavior
Posted:
Nov 21, 2012 9:25 AM
|
|
dpb <none@non.net> wrote in message <k8ine6$6i0$1@speranza.aioe.org>... > On 11/21/2012 7:41 AM, Amin Bashi wrote: > > Hi everyone > > I recently observed strange behavior of num2str function. As you see in > > below: > >>> c = [1 2; 3 4] > > > > c = > > > > 1 2 > > 3 4 > > > >>> double(num2str(c(1,:))) > > > > ans = > > > > 49 32 32 50 > > > > Obviously it put space between 1 and 2; > > what can i do to solve this problem? > > If you want a specific format, specify that format. num2str() converts > numeric values in a "pretty" format over which you have very little > control other than a precision. > > Use sprintf() instead-- > > double(sprintf('%d',c(1,:)) > > --
Thanks. But I don?t remember this side effect on older MATLAB versions. this is a better trick to solve the problem: num2str(c(1,:)')'
|
|
|
|