How to extract parts of an array by given logical conditions?

4 visualizaciones (últimos 30 días)
Hi, I have an array, let's say
M=
1 1 0
1 2 0
1 3 1
2 1 0
2 2 1
2 3 1
and I would like to create a new array only with the case for which the value of the third column equals 1. Thus
N=
1 3 1
2 2 1
2 3 1

Respuesta aceptada

Image Analyst
Image Analyst el 9 de Jun. de 2014
Try this:
M=[...
1 1 0
1 2 0
1 3 1
2 1 0
2 2 1
2 3 1]
rowsToExtract = M(:,3)==1;
N = M(rowsToExtract,:)
  1 comentario
Emerson De Souza
Emerson De Souza el 9 de Jun. de 2014
Thank you Image Analyst,
your suggestion elegantly solved my problem.
Wish you a nice day
Emerson

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Distribution Plots 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!

Translated by