For Programmers: Free Programming Magazines  


Home > Archive > Matlab > January 2008 > Clear vector for zeros?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Clear vector for zeros?
saneman

2008-01-13, 7:27 pm

I have this vector:

v = [1 2 3 5 0 0 8 9 8 7 0]

Is there some function in matlab that removes zeros from a vector so the
result would be:

v = [1 2 3 5 8 9 8 7]


Or do I need to make a for loop and check each element?
Shaun

2008-01-13, 7:27 pm

v(v~=0)
Yumnam Kirani Singh

2008-01-14, 4:38 am

Nice Trick Cyndie! What I usually do is
v=v(find(v~=0))
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com