Path: news.mathworks.com!not-for-mail
From: "david " <davidtra84@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: vectorising a simple loop
Date: Thu, 31 Mar 2011 08:32:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 19
Message-ID: <in1e65$s00$1@fred.mathworks.com>
Reply-To: "david " <davidtra84@gmail.com>
NNTP-Posting-Host: www-01-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1301560325 28672 172.30.248.46 (31 Mar 2011 08:32:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 31 Mar 2011 08:32:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2526093
Xref: news.mathworks.com comp.soft-sys.matlab:719262

Hi, I'm relatively new to matlab and just looking for some help in speeding up the process below. I believe that the for loop is what is causing the problem & would appreciate any help/input that could help speed up the process.

for the variables:
z is a single column vector ranging from -100 to +100 in a random order.
r=70;
y=45;

x=[-abs(z>r) , abs(z<-r)];
x=x(:,1)+x(:,2);

for i=1:length(x)-1;
             if       x(i)<0 && z(i+1)<y;
                      x(i+1)=-1;
             elseif  x(i)>0 && z(i+1)>-y;
                     x(i+1)=1;
             end
end

Thanks in advance.