Remove rows in cell array if specific column == 0

1 visualización (últimos 30 días)
Riccardo Rossi
Riccardo Rossi el 14 de Mzo. de 2019
Respondida: Alex Mcaulley el 14 de Mzo. de 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

Respuesta aceptada

Alex Mcaulley
Alex Mcaulley el 14 de Mzo. de 2019
This should work:
for ii=1:3
idx = find(D{1, ii}{2, 1}(:,4)==0);
D{1, ii}{2, 1}(idx,:) = [];
end

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by