From: Lisandro on 5 May 2010 14:57 Hi all, Does anyone knows how to decompose a number into digits, e.g. I have a column with the number 4321, and I want to decompose digit-wise into 4 columns, 4,3,2,1 Thanks! L
From: TideMan on 5 May 2010 15:40 On May 6, 6:57 am, "Lisandro " <lisandro.quino...(a)gmail.com> wrote: > Hi all, > > Does anyone knows how to decompose a number into digits, e.g. > > I have a column with the number 4321, and I want to decompose digit-wise into 4 columns, 4,3,2,1 > > Thanks! > L Use the ASCII coding: char(num2str(4321))-48
From: dpb on 5 May 2010 16:05 Lisandro wrote: .... > Does anyone knows how to decompose a number into digits, e.g. .... Seems to be popular, recently... For alternatives besides Tideman's answer, see thread "Return digits of a number as a list" just within the last week or so... --
From: Jan Simon on 5 May 2010 16:24 Dear Lisandro! > Does anyone knows how to decompose a number into digits, e.g. > I have a column with the number 4321, and I want to decompose digit-wise into 4 columns, 4,3,2,1 What is a "column with the number 4321" ? If I assume, you mean a scalar, then you could try to convert the number to a string temporarily: x = 4321 s = sprintf('%.16g', x) v = zeros(1, length(s)); for iv = 1:length(s) v(iv) = sscanf(s(iv), '%d', 1); end You can convert the chars in the string [s] directly also: v2 = s - '0' Is a homework? Kind regards, Jan
From: Lisandro on 5 May 2010 17:27 "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <hrsk54$rg8$1(a)fred.mathworks.com>... > Dear Lisandro! > > > Does anyone knows how to decompose a number into digits, e.g. > > I have a column with the number 4321, and I want to decompose digit-wise into 4 columns, 4,3,2,1 > > What is a "column with the number 4321" ? > If I assume, you mean a scalar, then you could try to convert the number to a string temporarily: > x = 4321 > s = sprintf('%.16g', x) > v = zeros(1, length(s)); > for iv = 1:length(s) > v(iv) = sscanf(s(iv), '%d', 1); > end > > You can convert the chars in the string [s] directly also: > v2 = s - '0' > > Is a homework? > > Kind regards, Jan No is not a homework...just curiosity, thanks all for your prompt replies!
|
Pages: 1 Prev: books on Matlab using control systems Next: need very quick help in grayscale image processing |