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

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

댓글을 달려면 로그인하십시오.

답변 (1개)

Jos (10584)
Jos (10584) 2018년 3월 14일

0 개 추천

a(~logical(a)) = []

댓글 수: 5

Sarumathi C
Sarumathi C 2018년 3월 14일
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) 2018년 3월 14일
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 2018년 3월 14일
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) 2018년 3월 14일
Please use valid matlab notation for the examples ...
Birdman
Birdman 2018년 3월 14일
편집: Birdman 2018년 3월 14일
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

질문:

2018년 3월 14일

편집:

2018년 3월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by