Remove rows in cell array if specific column == 0
1 view (last 30 days)
Show older comments
Riccardo Rossi
on 14 Mar 2019
Answered: Alex Mcaulley
on 14 Mar 2019
Hi everybody, i have a cell array like this:
D{1, 1}{2, 1} D{1, 2}{2, 1} D{1, 3}{2, 1}
12 6 78 1 13 6 78 1 13 6 78 1
16 9 79 1 18 7 75 1 13 6 78 1
26 6 84 1 22 9 74 0 13 6 78 0
32 4 88 0 20 6 83 0 20 6 83 0
62 2 68 1 12 6 78 1 20 6 83 0
I want to remove all rows with 4th column==0. I made the following script but it does not run:
for ii=1:3
for jj=1:5
if D{1, ii}{2, 1}(jj,4)==0
D{1, ii}{2, 1}(jj,:)=[]
end
end
end
The expected output is:
D{1, 1}{2, 1} D{1, 2}{2, 1} D{1, 3}{2, 1}
12 6 78 1 13 6 78 1 13 6 78 1
16 9 79 1 18 7 75 1 13 6 78 1
26 6 84 1 12 6 78 1
62 2 68 1
How can i do it? Thank you so much
0 Comments
Accepted Answer
Alex Mcaulley
on 14 Mar 2019
This should work:
for ii=1:3
idx = find(D{1, ii}{2, 1}(:,4)==0);
D{1, ii}{2, 1}(idx,:) = [];
end
0 Comments
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays 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!