How can I delete a row from a cell aray, with empty cell as first column

조회 수: 1 (최근 30일)
I have a cell aray with 2 columns.
A={[7;8],6;[],19;[3;4;5;6],11;[],25;[4;5],58;[],63}
I want to delete all rows which contain empty cells.How can I do that?

채택된 답변

Ken Atwell
Ken Atwell 2014년 3월 25일
편집: Ken Atwell 2014년 3월 25일
I think this is what you are after: The line of code below will call isempty on each row in the first column, and then trim A to only those rows that are not empty.
>> A(~cellfun(@isempty, A(:,1)), :)
ans =
[2x1 double] [ 6]
[4x1 double] [11]
[2x1 double] [58]
  댓글 수: 2
Dimitris Kokkinos
Dimitris Kokkinos 2014년 3월 25일
It was exactly what I was looking for.So simple,but so difficult to find. Thank you Ken.
Arnab Roy
Arnab Roy 2020년 12월 1일
Very elegant solution, thank you Ken!

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

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2014년 3월 25일
A(~any(cellfun(@isempty, A),2), :)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by