Generating vector with certain element of matrix

1 visualización (últimos 30 días)
Tanmoy
Tanmoy el 17 de Mayo de 2015
Comentada: Star Strider el 17 de Mayo de 2015
Say, I have a matrix M = [ 4 5; 10 4; 4 7; 20 6; 4 8 ] I wanna create a vector with 4 (4's that exist only in 1st column) I can't consider 4's from 2nd column of the matrix. Answer will be : V = [4 5 7 8]
By find function, I get [4 5 ; 4 7; 4 8] but how to store them as [4 5 7 8] ?
Another question: side = find(M(1,:) == 4) gives me [4 5 ; 4 7; 4 8]. I have [4 5] already. So, I only want [4 7; 4 8] as output So, how to exclude [4 5] , or first row. I am trying to apply ~ . But, how?

Respuesta aceptada

Star Strider
Star Strider el 17 de Mayo de 2015
This works:
A = [ 4 5; 10 4; 4 7; 20 6; 4 8 ];
N = 4;
Result = [N; A(A(:,1)==N,2)]';
With those column constraints, it is possible to use ‘logical indexing’ to get the result.
  2 comentarios
Tanmoy
Tanmoy el 17 de Mayo de 2015
Thank you so much.
Star Strider
Star Strider el 17 de Mayo de 2015
My pleasure.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by