From: "Steven_Lord" <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: matrix indexing
Date: Mon, 27 Feb 2012 09:23:49 -0500
Organization: MathWorks
Lines: 38
Message-ID: <jig3ll$k7d$>
References: <jif55e$jfa$>
Mime-Version: 1.0
Content-Type: text/plain;
Content-Transfer-Encoding: 7bit
X-Trace: 1330352629 20717 (27 Feb 2012 14:23:49 GMT)
NNTP-Posting-Date: Mon, 27 Feb 2012 14:23:49 +0000 (UTC)
In-Reply-To: <jif55e$jfa$>
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:759159

"merew " <> wrote in message 
> I want to fill a square matrix using nested for loops. I have the 
> following nested loop that computes the values to be filled in the matrix:
> D=zeros((L+1)^2,(L+1)^2);
> for l=0:L
> for m=-l:l
>     value=x;
>     D(?)=x;
> end
> end
> If L=2, the dimension of D is 3x3 and the nested for loops produce 9 
> values to be filled in the matrix D.
> Can somebody please help me?

Please do NOT both email me and post to the newsgroup; posting to the group 
is sufficient.

I recommend you review the section of the documentation that discusses 

Only you know how exactly you want to fill in D, so only you will be able to 
generate the necessary indices unless you show _the group_ what exactly 
you're trying to do.

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