Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Need to make code more Efficient
Date: Tue, 9 Feb 2010 10:36:04 +0000 (UTC)
Organization: University of Glasgow
Lines: 29
Message-ID: <hkrdqk$a6s$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1265711764 10460 172.30.248.35 (9 Feb 2010 10:36:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 9 Feb 2010 10:36:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1585470
Xref: news.mathworks.com comp.soft-sys.matlab:605680


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