find elements vector in a matrix

3 Ansichten (letzte 30 Tage)
Paul Rogers
Paul Rogers am 5 Nov. 2019
Kommentiert: Paul Rogers am 5 Nov. 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

Akzeptierte Antwort

Stephen23
Stephen23 am 5 Nov. 2019
Bearbeitet: Stephen23 am 5 Nov. 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 Kommentar
Paul Rogers
Paul Rogers am 5 Nov. 2019
this is exactley what I was looking for.
Thanks man, you made my day!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by