Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: vectorization suggestion
Date: Sun, 17 Jul 2011 00:40:13 +0000 (UTC)
Organization: Xoran Technologies
Lines: 17
Message-ID: <ivtb1d$ng6$1@newscl01ah.mathworks.com>
References: <ivt1so$1uu$1@newscl01ah.mathworks.com> <ivt9ek$jq3$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 1310863213 24070 172.30.248.47 (17 Jul 2011 00:40:13 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 17 Jul 2011 00:40:13 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: news.mathworks.com comp.soft-sys.matlab:736503

"Roger Stafford" wrote in message <ivt9ek$jq3$1@newscl01ah.mathworks.com>...
>
>   What's wrong with just using a simple for-loop?  It may be about as efficient as any vectorization and is a lot easier to code.
>
=========================

I agree that this might be a case of vectorization overkill. Nevertheless, the following might be a better alternative to a for-loop if the strings of zeros are all fairly short

v_end=v_orig;
idx=1;
while any(idx)
   
   s = circshift(v_end,[0,-1]);
   idx=s & ~v_end;
   v_end(idx)=s(idx);
   
end