Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: simple loop problem
Date: Thu, 20 Dec 2012 17:01:08 +0000 (UTC)
Organization: Mitre Corp
Lines: 37
Message-ID: <kavg8k$976$1@newscl01ah.mathworks.com>
References: <kavbd0$ji8$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1356022868 9446 172.30.248.47 (20 Dec 2012 17:01:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 20 Dec 2012 17:01:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2318
Xref: news.mathworks.com comp.soft-sys.matlab:785150

"payam " <payamvahdati@yahoo.com> wrote in message <kavbd0$ji8$1@newscl01ah.mathworks.com>...
> Hello all,
> I put my code here so you can understand better what i am looking for. This is my code :
> 
> Lambda= 0.785;
> k= 2*pi/Lambda;
> S = 40;
> a= 0.3;
> l = 10;
> theta0= atan (S/l);
> n= (S/a) ;
> s= theta/n ;
> I0 = 100;
> 
> for i=1:4*n
>     for j=1:n
>         I(i,j) = I0 *(sin((k*a/2)*sin(theta0-(j-i)*0.58)))/(k*a/2)*sin(theta0-(j-i)*0.58) ;
>         
>     end
> end
> 
> I want at the end to have data that contains : [ I(1,:), I(2,:), I(3,:), ..... , I(4n,:) ]
> it means I want 4n numbers that are the sum up of all the js for each individual i.

% I don't have MATLAB installed on this computer, 
% but one of:

doc sum
doc cumsum

% should help you and get you started.
% BTW, there are many improvements you can make to the above code.
% For one, I suggest preallocating I.  Something like:

I = zeros(size(4*n,n))

% before the for loop.