How to convert a matrix like this?

Hello everyone, I need a help with this problem. I would like to convert a matrix to another one, like the following examples: A=[1;2;3;0;5;7]----->A=[1;2;3;5;7] B=[0;1;3;4;5;6]---->B=[1;3;4;5;6] That means I have a new matrix without 0. Thank you very much!

 Accepted Answer

madhan ravi
madhan ravi on 4 Sep 2018
Edited: madhan ravi on 4 Sep 2018
Try this:
A(A==0)=[]

6 Comments

If it works please accept the answer.
Thank you so much!???
You're welcome :)
A much simpler way:
A = nonzeros(A)
Thank you @Guillaume :)
Thank you ?

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!