Filter löschen
Filter löschen

How to find the value of a matrix in a specific position?

1 Ansicht (letzte 30 Tage)
abbxucy11
abbxucy11 am 13 Sep. 2016
Bearbeitet: Stephen23 am 13 Sep. 2016
I have a matrix A with the positions (361x2) stored and i want to find the values of another matrix B in the specific positions ..how can i do it?
  2 Kommentare
abbxucy11
abbxucy11 am 13 Sep. 2016
I have this code here and i found the location of all the values from -180 to 180 and stored them using the save command. It saves the locations in a function named find_results that is a matrix 361x2.
or=flow.Orientation; ordeg=(180*or)/pi; ORIENT=round(ordeg)
for a= 180:-1:-180
[i,j]=find(ORIENT==a)
end
save('test.mat','i','j')
Then, i have another matrix named magnitude and i want to find the values of each location that there is in the find_results matrix

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Adam
Adam am 13 Sep. 2016
sz = size( B );
idx = sub2ind( sz, A(:,1), A(:,2) );
res = B( idx );

Weitere Antworten (1)

Stephen23
Stephen23 am 13 Sep. 2016
Bearbeitet: Stephen23 am 13 Sep. 2016
You can use sub2ind:
idx = sub2ind(size(B), A(:,1), A(:,2));
out = B(idx);

Kategorien

Mehr zu Cell 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