delete rows in a cell array
이전 댓글 표시
having a cell array containing in 1st column a name of a country and in next column values, how can I delete rows containing 1 or more zeros values?
댓글 수: 1
Stephen23
2019년 1월 29일
@Anastasia Anastasiadou: please upload your data in a .mat file by clicking the paperclip button.
채택된 답변
추가 답변 (2개)
Omer Yasin Birey
2019년 1월 29일
편집: Omer Yasin Birey
2019년 1월 29일
Lets say your cell array's variable name is 'a'
a = a(all(cellfun(@(x)x~=0,a),2),:);
댓글 수: 5
Anastasia Anastasiadou
2019년 1월 29일
madhan ravi
2019년 1월 29일
you mean if there is any zero in the row you want to delete it?
Anastasia Anastasiadou
2019년 1월 29일
Omer Yasin Birey
2019년 1월 29일
That should work
remZeros = a(all(cellfun(@(x)x~=0,a),2),:);
remZeros(2:end+1,:) = remZeros(1:end,:);
remZeros(1,:) = a(1,:);
Anastasia Anastasiadou
2019년 1월 29일
KSSV
2019년 1월 29일
Let A be your matrix with size (m,n)
idx = A==0 ;
A(sum(A,2)~=n,:) = [] ;
댓글 수: 2
madhan ravi
2019년 1월 29일
? OP has mentioned it’s a cell array not a matrix.
Anastasia Anastasiadou
2019년 1월 29일
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
