Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: vectorization problem
Replies: 1   Last Post: Dec 12, 1996 2:20 PM

 Pope P. Britt Posts: 134 Registered: 12/7/04
Re: vectorization problem
Posted: Dec 12, 1996 2:20 PM

lsi@itk.unit.no (Lars Struen Imsland) wrote:

>In article <58ogjd\$rud@sun.rhrk.uni-kl.de>, litzinge@rhrk.uni-kl.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:n-1).*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
e-mail: pete@electrosystems.com