Raise the zeros in the vector up

If I have a vector [5 8 0 7 9 0 3], how do I put it this way: [0 0 5 8 7 9 3] use only function if-else
thank you.

 Accepted Answer

Something like this,
v = [5 8 0 7 9 0 3]
ind = v==0;
v = [v(ind) v(~ind)]

1 Comment

Thanks! But if I want it to work for any vector / matrix?
For example: [5 8 0 7 9 0 3] ' it will not work

Sign in to comment.

More Answers (0)

Categories

Find more on Vehicle Dynamics Blockset in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!