Remove rows in cell array if specific column == 0
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Riccardo Rossi
am 14 Mär. 2019
Beantwortet: Alex Mcaulley
am 14 Mär. 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 Kommentare
Akzeptierte Antwort
Alex Mcaulley
am 14 Mär. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!