Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: for loop matrix
Date: Thu, 10 Mar 2011 05:09:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 37
Message-ID: <il9mdh$r2d$1@fred.mathworks.com>
References: <il9l65$7ao$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1299733745 27725 172.30.248.37 (10 Mar 2011 05:09:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 10 Mar 2011 05:09:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2021205
Xref: news.mathworks.com comp.soft-sys.matlab:714948

"Jong Hoong " <jonghoong@hotmail.com> wrote in message <il9l65$7ao$1@fred.mathworks.com>...
> Hi all,
> how would i create a for loop matrix like this:
> 
> A = [1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;...
>     0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;...
>      0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0;...
>      0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0;...
>      0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0;...
>      0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0;...
>      0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0;...
>      0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0;...
>      0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0;...
>      0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1];
> 
> size(A)= [10 20]
> I tried this where my m=2, n= 20:
> 
> A = [ones(1,m) zeros(1,n-m);...
>     zeros(1,m) ones(1,m) zeros(1,n-2*m);...
>     zeros(1,2*m) ones(1,m) zeros(1,n-3*m);...
>     zeros(1,3*m) ones(1,m) zeros(1,n-4*m);...
>     zeros(1,4*m) ones(1,m) zeros(1,n-5*m);...
>     zeros(1,5*m) ones(1,m) zeros(1,n-6*m);...
>     zeros(1,6*m) ones(1,m) zeros(1,n-7*m);...
>     zeros(1,7*m) ones(1,m) zeros(1,n-8*m);...
>     zeros(1,8*m) ones(1,m) zeros(1,n-9*m);...
>     zeros(1,9*m) ones(1,m)];
> 
> and now, how would I use for loop to create the matrix if i wan my 
> size(A) to be flexible so that I can create larger matrix?

a=zeros(10,20);
for l=1:size(a,1)
a(l,2*l-1)=1;
a(l,2*l)=1;
end