How to eliminate zeros from array

e.g I want to make this:
1,1,1,1,0,0 1,1,0,0,0,0 1,0,0,0,0,0 1,1,1,1,1,0 into this:
1,1,1,1 1,1 1 1,1,1,1,1

1 Comment

Can you give a an example of these two arrays in working matlab code?
Array1 = ...
Array2 = ...

Sign in to comment.

Answers (1)

a(~logical(a)) = []

5 Comments

Sir the all values coming in single column but I need location of non zero values not change and only zeros should be eliminated to find difference between two rows when both row have same number of non zero values
You cannot simply eliminate elements in a regular array without changing the shape, you should replace them by something else.
What do you exactly mean by " find difference between two rows " ?
My output like 2 0 0 0; 5 5 0 0; 6 7 0 0; 1 5 8 0; I need to covert like 2; 5 5; 6 7; 1 5 8; I need to find out the difference between the 2nd row and 3rd row because 1St have different length comparing with second row but 2&3 have same length of values so I need output like 2; 1{(6-5)} {(7-2)} 2; 1 5 8;
Please use valid matlab notation for the examples ...
Birdman
Birdman on 14 Mar 2018
Edited: Birdman on 14 Mar 2018
And maybe this should be a new question since it is hard to pay attention to this between comments, also you are off the topic of the question.

Sign in to comment.

Products

Asked:

on 14 Mar 2018

Edited:

on 14 Mar 2018

Community Treasure Hunt

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

Start Hunting!