From: mee gestaf on
How can I transform a number ex: 12345 into a vector ex [1 2 3 4 5]
From: Walter Roberson on
mee gestaf wrote:
> How can I transform a number ex: 12345 into a vector ex [1 2 3 4 5]

textscan(sprintf('%d',TheNumber), '%1d', 'Combine', 1)

Note that is a percent-one-dee, not percent-lowercase-ell-dee .

The result will probably be a cell array containing the vector that you
want.
From: James Tursa on
"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
From: mee gestaf on
"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.
From: Mark Shore on
"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.