Remove rows in cell array if specific column == 0

1 view (last 30 days)
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

Accepted Answer

Alex Mcaulley
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

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!