From: "Steven_Lord" <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to enter conditional matrix
Date: Fri, 30 Mar 2012 09:19:09 -0400
Organization: MathWorks
Lines: 25
Message-ID: <jl4bsd$7b3$>
References: <jl4amv$2ng$>
Mime-Version: 1.0
Content-Type: text/plain;
Content-Transfer-Encoding: 7bit
X-Trace: 1333113549 7523 (30 Mar 2012 13:19:09 GMT)
NNTP-Posting-Date: Fri, 30 Mar 2012 13:19:09 +0000 (UTC)
In-Reply-To: <jl4amv$2ng$>
X-Priority: 3
X-MSMail-Priority: Normal
Importance: Normal
X-Newsreader: Microsoft Windows Live Mail 14.0.8089.726
X-MimeOLE: Produced By Microsoft MimeOLE V14.0.8089.726
Xref: comp.soft-sys.matlab:762676

"Kennedy Kwasi" <> wrote in message 
> How do i write a matlab script to generate an 80x80 matrix to satisfy the 
> following conditions:
> for i=1:80; for j=1:80 , if j==i , a(i,j)=2*i
> else if j=i+2, for i=1:78 or j=i-2, for i=3:80, a(i,j)=0.5*i
> else if j=i+4, for i=1:76 or j=i-2, for i=5:80, a(i,j)=0.25*i
> else a(i,j)=0

No idea, because it looks like you're trying to nest a FOR loop over i 
inside another FOR loop also over i.

If I had to guess I'd say the function you're looking for is DIAG, but if 
you could show the group a small example (say 8-by-8) of the matrix you want 
to result from running the code, the group may be able to offer more 
specific help.

Steve Lord
To contact Technical Support use the Contact Us link on