Delete row when one cell is empty

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 Comment

Please post a meaningful example, your code and explain, what "can't seem to get the right result" explicitly means.

Sign in to comment.

 Accepted Answer

Jan
Jan on 6 May 2019
Edited: Jan on 6 May 2019
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 Comments

Pauli
Pauli on 6 May 2019
Edited: Pauli on 6 May 2019
Sorry, here some more details: I have a double consisting of two rows. In one of those rows I remove all values that are smaller than 0.5 and I want to delete the corresponding values in the other row so that the two columns have the same length again.
Tried using this for the deletion: probs(probs(:,2) < 0.5) = [];
Do you mean:
probs(probs(:,2) < 0.5, :) = [];
% ^
Just found the mistake too. Thank you!

Sign in to comment.

More Answers (0)

Categories

Asked:

on 6 May 2019

Commented:

on 6 May 2019

Community Treasure Hunt

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

Start Hunting!