# Converting a the result vector from logical indexing into a matrix possible or unnescesary?

1 visualización (últimos 30 días)
Daniel el 4 de Dic. de 2013
Comentada: Daniel el 7 de Dic. de 2013
Hello everyone,
I need to extract rows of a matrix with a certain value in one column. At the moment I am using logical indexing i this way:
c=A(:,2)==3; T=A([c,c,c,c]);
The problem I have is that T is a vector, with the columns added end to end, but I need it as a matrix.
Does Matlab provide an easy way to convert such a vector to a matrix or is there another easy way to extract the rows into a matrix?
Thank you everybody.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Andrei Bobrov el 4 de Dic. de 2013
T = A(A(:,2) == 3,:);
##### 2 comentariosMostrar NingunoOcultar Ninguno
Daniel el 7 de Dic. de 2013
Sorry doesn't work. I get
T =
Empty matrix: 0-by-10
as a result.
Thanks anyway.
Daniel el 7 de Dic. de 2013
Works like a charm, if i use the correct data. Thanks again.

Iniciar sesión para comentar.

### Más respuestas (1)

Jos (10584) el 7 de Dic. de 2013
Often, you get some insight when you remove the semi-colons
A = [1 2 3 4 ; 11 3 13 14 ;21 22 23 24 ; 41 3 43 44] % example data
c = A(:,2)==3
T = A(c,:)
if T is empty, there are simply no rows that have a value of 3 in the second column.
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Daniel el 7 de Dic. de 2013
Sorry was using the wrong matrix. The first answer works just fine. To much data and I lost track of what is what. Thanks to both of you.

Iniciar sesión para comentar.

### Categorías

Más información sobre Data Type Conversion 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