Path: news.mathworks.com!newsfeed-00.mathworks.com!NNTP.WPI.EDU!elk.ncren.net!newsflash.concordia.ca!canopus.cc.umanitoba.ca!not-for-mail
From: Walter Roberson <roberson@hushmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Need to make code more Efficient
Date: Tue, 09 Feb 2010 16:29:27 -0600
Organization: Canada Eat The Cookie Foundation
Lines: 31
Message-ID: <hkso3n$dea$1@canopus.cc.umanitoba.ca>
References: <hkrdqk$a6s$1@fred.mathworks.com>
NNTP-Posting-Host: ibd-nat.ibd.nrc.ca
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: canopus.cc.umanitoba.ca 1265755063 13770 192.70.172.18 (9 Feb 2010 22:37:43 GMT)
X-Complaints-To: abuse@cc.umanitoba.ca
NNTP-Posting-Date: Tue, 9 Feb 2010 22:37:43 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.23 (X11/20090817)
In-Reply-To: <hkrdqk$a6s$1@fred.mathworks.com>
Xref: news.mathworks.com comp.soft-sys.matlab:605933


Fraser Dickson wrote:

>            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

r2_r1 = temp_array(d_under_test - cd - kd : ...
                    d_under_test + cd + kd, ...
                    r_under_test);
r2mean = mean(r2_r1(1:kd));
r1mean = mean(r2_rw(end-kd-1:end));
average(x,y) = (r1mean + r2mean) / 2;


Note: because kr and cr do not vary according to y, you can vectorize to do an 
entire column at one time.

Also note that you could move the initialization of d_under_test to outside of 
the 'for y' loop.

>            r2mean = mean(r2);
>            r1mean = mean(r1);
>            average(x,y) = 0.5*(r1mean+r2mean);
>     end
>    end