find elements vector in a matrix

3 visualizaciones (últimos 30 días)
Paul Rogers
Paul Rogers el 5 de Nov. de 2019
Comentada: Paul Rogers el 5 de Nov. de 2019
Hi,
I have a matrix A 3x1201 and a vector B 3 elements. (A and B can change size but B will alway have the size of A row's).
B contains the indexes of the column in A I am intrested in.
First element of B is the index of the first row in a
Second elemnt of B is the index of the second row in A.
Third elemnt in B is the index of the third row in A.
How do I store in a new vector?
I Attached A and B to the post.
Thank You everybody!
In short I have to store in a new vector the elements:
A[1,1118]
A[2,1124]
A[3,1132]
B =
1118 1124 1132

Respuesta aceptada

Stephen23
Stephen23 el 5 de Nov. de 2019
Editada: Stephen23 el 5 de Nov. de 2019
Simply use sub2ind like this:
>> idx = sub2ind(size(psic_pos),1:size(psic_pos,1),loc);
>> vec = psic_pos(idx)
vec =
0.99353 1.0201 1.1786
And checking (the 2nd row):
>> psic_pos(2,1124)
ans =
1.0201
  1 comentario
Paul Rogers
Paul Rogers el 5 de Nov. de 2019
this is exactley what I was looking for.
Thanks man, you made my day!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays 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