delete first x number of rows from a cell array
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Shima Asaadi
el 25 de Mzo. de 2016
Comentada: Shima Asaadi
el 25 de Mzo. de 2016
I have a 2000*4 cell array. The 4th column is an ascending numeric values from 0 to 30. I do not know how many rows have 0 value in 4th column, and I would like to delete those rows from cell array. I wrote the following code with the loop, which works well. But is there any efficient way to avoid the for-loop?
[m,n]=size(A);
count = 0;
for i=1:m
if isequal(A{i,4},0)
count = count+1;
end
end
A = A(count+1:m,:)
Thank you in advance
0 comentarios
Respuesta aceptada
Stephen23
el 25 de Mzo. de 2016
>> C = num2cell([randi(9,6,3),[0;0;0;1;2;3]])
C =
[5] [8] [6] [0]
[2] [3] [5] [0]
[2] [9] [4] [0]
[3] [4] [8] [1]
[8] [2] [6] [2]
[3] [3] [5] [3]
>> C([C{:,4}]>0,:)
ans =
[3] [4] [8] [1]
[8] [2] [6] [2]
[3] [3] [5] [3]
0 comentarios
Más respuestas (1)
Jos (10584)
el 25 de Mzo. de 2016
Each cell in the 4th row of A should contain a scalar, being 0 or another value
tf = [A{:,4}] ~= 0
Aout = A(tf,:)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!