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 commentaire

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

Connectez-vous pour commenter.

Réponses (1)

Jos (10584)
Jos (10584) le 14 Mar 2018
a(~logical(a)) = []

5 commentaires

Sarumathi C
Sarumathi C le 14 Mar 2018
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
Jos (10584)
Jos (10584) le 14 Mar 2018
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 " ?
Sarumathi C
Sarumathi C le 14 Mar 2018
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;
Jos (10584)
Jos (10584) le 14 Mar 2018
Please use valid matlab notation for the examples ...
Birdman
Birdman le 14 Mar 2018
Modifié(e) : Birdman le 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.

Connectez-vous pour commenter.

Produits

Modifié(e) :

le 14 Mar 2018

Community Treasure Hunt

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

Start Hunting!

Translated by