Delete row when one cell is empty

조회 수: 2 (최근 30일)
Pauli
Pauli 2019년 5월 6일
댓글: Pauli 2019년 5월 6일
Hi,
I'm trying to delete those rows in an array that contain one empty cell. I have only to columns.
Is there an easy way to do this? I tried using ismissing() with an if statement, but can't seem to get the right result.
Thank you!
  댓글 수: 1
Jan
Jan 2019년 5월 6일
Please post a meaningful example, your code and explain, what "can't seem to get the right result" explicitly means.

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

채택된 답변

Jan
Jan 2019년 5월 6일
편집: Jan 2019년 5월 6일
Perhaps:
C = {'a', 'b'; ...
[], 'c'; ...
'd', 'q'}
m = any(cellfun('isempty', C), 2); % Any cell in row is empty
C(m, :) = []
You wrote "one empty cell". This might mean:
C = {'a', 'b'; ...
{}, 'c'; ...
[], 'q'}
And you want to remove the 2nd row only, because you mean really an empty cell, but not the empty matrix. Maybe you want to keep the row, if it contains 2 empty cell, oder at least one empty array. Please explain this exactly.
  댓글 수: 3
Jan
Jan 2019년 5월 6일
Do you mean:
probs(probs(:,2) < 0.5, :) = [];
% ^
Pauli
Pauli 2019년 5월 6일
Just found the mistake too. Thank you!

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

추가 답변 (0개)

카테고리

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