Prev: simulink - store data for a certain period of time and then use it
Next: How to combine volume and surface area calculations for adjacentsets of data
From: mee gestaf on 17 May 2010 12:12 How can I transform a number ex: 12345 into a vector ex [1 2 3 4 5]
From: Walter Roberson on 17 May 2010 12:17 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 17 May 2010 12:21 "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 17 May 2010 12:29 "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 17 May 2010 13:12
"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. |