Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: num2sr strange behavior
Replies: 6   Last Post: Nov 21, 2012 10:04 AM

 Messages: [ Previous | Next ]
 Amin Bashi Posts: 10 Registered: 11/23/07
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.
>
>
> 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,:)')'

Date Subject Author
11/21/12 Amin Bashi
11/21/12 Nasser Abbasi
11/21/12 dpb
11/21/12 Amin Bashi
11/21/12 dpb
11/21/12 dpb
11/21/12 Amin Bashi