Matrix operations without loop.
Afficher commentaires plus anciens
Hi everyone,
Let say A is the matrix of size 100 x 100 , A is kind of lookup table.
and There is an other matrix B that has the size let say 10 x 100. Where each col is histogram. Now for Query col vector Q size of 10 x 1. I want to get resultant matrix R of size(B), where each cell value in R, is obtained by looking the values of Q and B in A. let say:
R(1,1) = A( Q(1), B(1,1));
R(5,5) = A(Q(5)), B(5,5));
For sure, the values in B and Q are in range of A indexes. I hope you understand the scenario. Thanks a lot in advance.
3 commentaires
Walter Roberson
le 27 Nov 2011
Either I do not understand or else there is a problem with your specification.
Suppose you are indexing A(Q(K), B(L,M)) then apparently the answer is to get stored in R(K, something), but I cannot tell whether it is supposed to go in R(K,L) or in R(K,M), or whether L and M will always be the same making the two possible destinations equal ?
Walter Roberson
le 27 Nov 2011
Or is it that K and L will always be the same and the answer would go in R(K,M) ?
Junaid
le 27 Nov 2011
Réponse acceptée
Plus de réponses (1)
N Madani SYED
le 27 Nov 2011
I think the following should work
for i = 1:10
for j = 1:100
m = Q(i);
n = B(i,j);
R(i,j)= A(m,n);
end
end
1 commentaire
Junaid
le 27 Nov 2011
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!