MATLAB: Remove rows in cell array if specific column == 0

cell arraycell arraysMATLAB

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

Best Answer

This should work:
for ii=1:3
idx = find(D{1, ii}{2, 1}(:,4)==0);
D{1, ii}{2, 1}(idx,:) = [];
end