Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: Separating numbers in a matrix
Posted:
May 23, 2012 5:04 AM


"Nasser M. Abbasi" <nma@12000.org> wrote in message <jphht6$5r3$1@speranza.aioe.org>... > On 5/22/2012 8:39 PM, Galam Lee wrote: > > Hello all > > > > I have a matrix as below. > > A=[45 50; 200 205; 355 433] > > > > I would like to separate the numbers from the matrix and make > >two new matrixes which contain 2digit numbers. > > eg) A1=[45 50 ;00 05; 55 33] > > A2=[00 00; 02 02; 03 04] > > > > How can I do this? > > > > Kind regards, > > Galam Lee > > I am lazy now. Here is my brain dead solution: > >  > A=[45 50; 200 205; 355 433]; > > A1=zeros(size(A)); > A2=zeros(size(A)); > > for i = 1:size(A,1) > for j = 1:size(A,2) > > x = num2str(A(i,j)); > N = length(x); > if N>2 > A2(i,j) = str2double(x(1:N2)); > A1(i,j) = str2double(x(N1:N)); > else > A1(i,j) = str2double(x); > end > > end > end > > A1 > A2 >  > > A1 = > > 45 50 > 0 5 > 55 33 > > > A2 = > > 0 0 > 2 2 > 3 4 > > > I am sure there is a much smarter way of doing it. > > Nasser
Thank you for your reply :) It runs well!



