Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Pope P. Britt

Posts: 134
Registered: 12/7/04
Re: vectorization problem
Posted: Dec 12, 1996 2:20 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.