Effacer les filtres
Effacer les filtres

Extracting specific values from a Matrix

1 vue (au cours des 30 derniers jours)
Antonio Sarusic
Antonio Sarusic le 21 Fév 2020
Commenté : Antonio Sarusic le 21 Fév 2020
Hello,
I have a vector (1x1280; contains indices) and a matrix (1024x1280).
Now I want to extract for each column of the matrix, the value that is at the index contained in my index vector.
This may not be entirely understandable so here is an example:
In the first column of my vector I have the value 450. So I want to know what the value of my matrix in the first column in the row 450 is.
In the second column of my vector I have the value 837. So I want to know what the value of my matrix in the second column in the row 837 is.
And so on.
Thanks a lot
Antonio

Réponse acceptée

Stephen23
Stephen23 le 21 Fév 2020
Modifié(e) : Stephen23 le 21 Fév 2020
Use sub2ind:
>> V = randi(1024,1,1280); % fake vector of row indices.
>> M = rand(1024,1280); % fake matrix of data.
>> S = size(M);
>> X = sub2ind(S,V,1:S(2));
>> Z = M(X);
And checking:
>> Z(1)
ans = 0.40058
>> M(V(1),1)
ans = 0.40058

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by