delete rows in a cell array

조회 수: 3 (최근 30일)
Anastasia Anastasiadou
Anastasia Anastasiadou 2019년 1월 29일
편집: madhan ravi 2019년 1월 30일
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
Stephen23 2019년 1월 29일
@Anastasia Anastasiadou: please upload your data in a .mat file by clicking the paperclip button.

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

채택된 답변

madhan ravi
madhan ravi 2019년 1월 29일
편집: madhan ravi 2019년 1월 29일
C={'country1' 11 33 55 40
'country2' 22 0 0 0
'country3' 58 44 55 5 };
idx=cellfun(@all,C,'un',0);
C(~all(cell2mat(idx),2),:)=[]
  댓글 수: 10
Anastasia Anastasiadou
Anastasia Anastasiadou 2019년 1월 29일
편집: madhan ravi 2019년 1월 30일
yeeeees! it worked!!!
thank you so muchh
madhan ravi
madhan ravi 2019년 1월 29일
편집: madhan ravi 2019년 1월 29일
Help us to help you! , that's why we ask you to upload the required files at he very beginning when you ask a question so that a fast solution can be provided.

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

추가 답변 (2개)

Omer Yasin Birey
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
Omer Yasin Birey
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
Anastasia Anastasiadou 2019년 1월 29일
it does not.
Error using cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
and although I set uniformoutput to false again nothing

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


KSSV
KSSV 2019년 1월 29일
Let A be your matrix with size (m,n)
idx = A==0 ;
A(sum(A,2)~=n,:) = [] ;
  댓글 수: 2
madhan ravi
madhan ravi 2019년 1월 29일
? OP has mentioned it’s a cell array not a matrix.
Anastasia Anastasiadou
Anastasia Anastasiadou 2019년 1월 29일
I have a cell array so the == does not work ! :)

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

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by