Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Need to make code more Efficient
Date: Tue, 9 Feb 2010 12:49:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 42
Message-ID: <hkrlju$jsr$1@fred.mathworks.com>
References: <hkrdqk$a6s$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 1265719742 20379 172.30.248.37 (9 Feb 2010 12:49:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 9 Feb 2010 12:49:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1886545
Xref: news.mathworks.com comp.soft-sys.matlab:605719


"Fraser Dickson" 
> Hi i have a piece of code that looks through a data set and works out the average value for each cell based on the values sourrounding that cell ( 10 cells above and 10 cells below averaged).  The data set is extremely large ( roughly 500 x 40)  so i was wondering if anyone could reccomend how i can speed up my code.  I have a lot of for loops and im sure there is nothing efficient about that !
> 
> Thanks
> 
> average = zeros(500,40);
>  r1 = zeros(kd,1);
>  r2 = zeros(kd,1);
>    
>  for x = 1:40
>         for y = 1 : 500
> 
>             d_under_test = x+kd+cd;
>             r_under_test = y +kr+cr;
> 
> 
> 
>             for counter = 1:kd
>                 r1(counter) = temp_array((d_under_test + cd  +counter ),(r_under_test));
>             end
> 
>             for counter = 1:kd
>                 r2(counter) = temp_array((d_under_test - cd  -counter ),(r_under_test));
>             end
> 
>             r2mean = mean(r2);
>             r1mean = mean(r1);
>             average(x,y) = 0.5*(r1mean+r2mean);
>      end
>     end

"The data set is extremely large ( roughly 500 x 40) ."
Huge is when you have a 100e6 by 20 matrix... 

Plz post the result of:
whos kd 
whos cd

You should definitely forget your approach. Read this useful doc:
http://www.mathworks.com/support/tech-notes/1100/1109.html

Oleg