How to delete specific cells according to the condition from cell array?
Show older comments
I have a cell array test (4x189).
Each cell is a double array of different sizes. I want to delete all the cells, that look like this (basically, they are all 7x4, the same looking, but different numbers):
NaN 1 0.437500000000000 0
NaN NaN NaN NaN
NaN NaN NaN NaN
NaN 8 NaN NaN
NaN 719 NaN NaN
NaN 719 NaN NaN
NaN NaN NaN NaN
Could you, please, help me to do that?
Thank you so much!
3 Comments
the cyclist
on 23 Sep 2021
Edited: the cyclist
on 23 Sep 2021
You have not yet given us enough information to figure out which elements to keep.
What is the defining characteristic that differentiates the arrays you want to keep, from the arrays you do not?
Did you mean that all "bad" arrays are 7x4, and all "good" arrays are a different size?
Or are some of the "good" arrays also 7x4, but do not have NaN?
Also, suppose you "delete" only the upper-left element. What do you mean by that? The cell array will still need to be 4x189, so how do you "delete" it? Replace that element with an empty array?
CheshireM
on 23 Sep 2021
Accepted Answer
More Answers (1)
Chunru
on 24 Sep 2021
If you want to keep the output as a cell array (as the input), you cannot delete them, but you can assign them to empty array.
for j=1:189
for i=1:4
if all(size(test{i,j})==[7 4]) && test{i,j}(5,2)==test{i,j}(6,2)
test{i,j} = [];
end
end
end
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!