delete zeros from matrix
Mostrar comentarios más antiguos
How do I delete all the columns that have zeros with a for loop? I tried reducing the number of columns by one in every iteration but matlab shows me "index exceeds matrix dimentions".
p4 = [0 0 31 37 43 47; 0 0 19 13 7 3];
grammes = size(p3,1);
sthles = size(p3,2);
for i = 1 : grammes
for j = 1 : sthles
if iszero(p3(i,j)) == 1
p3(:,j) = [];
sthles = sthles - 1
end
end
end
1 comentario
Maria K
el 23 de Jul. de 2020
Respuesta aceptada
Más respuestas (1)
madhan ravi
el 23 de Jul. de 2020
p4(:, all(p4 == 0)) = []
1 comentario
Maria K
el 23 de Jul. de 2020
Categorías
Más información sobre Numerical Integration and Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!