From: James Tursa on
"Mark Shore" <mshore(a)magmageosciences.ca> wrote in message <hsrtd5$kb2$1(a)fred.mathworks.com>...
> "mee gestaf" <metallheart_18(a)yahoo.com> wrote in message <hsrqsj$a7e$1(a)fred.mathworks.com>...
> > "James Tursa" <aclassyguy_with_a_k_not_a_c(a)hotmail.com> wrote in message <hsrqe0$60u$1(a)fred.mathworks.com>...
> > > "mee gestaf" <metallheart_18(a)yahoo.com> wrote in message <hsrpsk$nv1$1(a)fred.mathworks.com>...
> > > > How can I transform a number ex: 12345 into a vector ex [1 2 3 4 5]
> > >
> > > >> x = 12345
> > > x =
> > > 12345
> > > >> num2str(x) - '0'
> > > ans =
> > > 1 2 3 4 5
> > >
> > > James Tursa
> >
> >
> > THANKS, THAT IS SIMPLE.
>
> OK, simple but NOT obvious. It took me a while to see how this trick works, and why '12345' - '0' does not equal '12345' + '0'. A hint, 'b' - 'a' = 'c' - 'b' = 1.

I suppose I should point out that the "trick" works because the character encoding scheme in use has the characters '0', '1', ..., '9' all next to each other and different by 1. e.g., this is true of ASCII and EBCDIC encoding. Also, subtracting character values in MATLAB automatically promotes the result to a double type.

James Tursa
From: Mark Shore on
>
> I suppose I should point out that the "trick" works because the character encoding scheme in use has the characters '0', '1', ..., '9' all next to each other and different by 1. e.g., this is true of ASCII and EBCDIC encoding. Also, subtracting character values in MATLAB automatically promotes the result to a double type.
>
> James Tursa

Maybe, this being a newsgroup with much potential for miscommunication, I should say that "trick" was not meant in a derogatory sense.

"Ingenious use of relatively cryptic MATLAB functionality", maybe?
From: James Tursa on
"Mark Shore" <mshore(a)magmageosciences.ca> wrote in message <hssgcj$9h8$1(a)fred.mathworks.com>...
> >
> > I suppose I should point out that the "trick" works because the character encoding scheme in use has the characters '0', '1', ..., '9' all next to each other and different by 1. e.g., this is true of ASCII and EBCDIC encoding. Also, subtracting character values in MATLAB automatically promotes the result to a double type.
> >
> > James Tursa
>
> Maybe, this being a newsgroup with much potential for miscommunication, I should say that "trick" was not meant in a derogatory sense.

No offense taken ... I sometimes "post-in-haste" and additional enlightening comments by others never hurt :)

James Tursa