Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: vectorization problem
Posted:
Dec 12, 1996 2:20 PM


lsi@itk.unit.no (Lars Struen Imsland) wrote:
>In article <58ogjd$rud@sun.rhrk.unikl.de>, litzinge@rhrk.unikl.de (Wolfgang Litzinger [ET]) writes: >> Hi folks >> >> I have a very large vektor containing integers and I want to do the >> following (fast!) >> >> 1. if there a two following ones I want to delete them
>a=x==1; >k=find(a(1:length(a)1).*a(2:length(a)))
>> >> 2 if there is a 2 I want to replace the 2 by [2 2 2]
>Is this possible (vectorized) ? Are there rules for which problems that >are "vectorizable" ?
>> >> so if x = [1 3 2 3 1 1 4 5 1 2 ...] >> >> there should be >> >> result = [1 3 2 2 2 3 4 5 1 2 2 2 ... >> Building upon previous post:
x=[1 3 2 3 1 1 4 5 1 2] [m,n]=size(x) a=x==1; k=find(a(1:n1).*a(2:n)) x([k k+1]) = [] %%% new code
[m,n]=size(x) f=find(x==2) x=[x;zeros(2,n)] x(:,f)=2*ones(size(x(:,f))) x(x==0)=[]
 Pete Britt email: pete@electrosystems.com



