How to remove some elements from a matrix?
Mostrar comentarios más antiguos
Hi everyone
Now I have a matrix which has two columns and several rows.
How can I remove the rows which contains value that read 0 and create a new matrix?
Any help would be really appreciated!
Respuesta aceptada
Más respuestas (1)
We can do this simply using all and logical indexing, which is faster than using find and also allows us to allocate directly to a new matrix:
>> M = randi([0,5], 8, 2)
M =
2 4
5 4
4 4
5 2
3 3
0 1
5 4
5 0
>> N = M(all(M~=0,2),:)
N =
2 4
5 4
4 4
5 2
3 3
5 4
1 comentario
Jarvis Huang
el 23 de Abr. de 2015
Categorías
Más información sobre Logical 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!