Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Separating numbers in a matrix
Date: Wed, 23 May 2012 09:04:07 +0000 (UTC)
Organization: &#49436;&#50872;&#45824;&#54617;&#44368;
Lines: 64
Message-ID: <jpi967$kpt$1@newscl01ah.mathworks.com>
References: <jphf3r$9no$1@newscl01ah.mathworks.com> <jphht6$5r3$1@speranza.aioe.org>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1337763847 21309 172.30.248.37 (23 May 2012 09:04:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 23 May 2012 09:04:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 3277071
Xref: news.mathworks.com comp.soft-sys.matlab:768717

"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 2-digit 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:N-2));
>             A1(i,j) = str2double(x(N-1: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!