フィルターのクリア

Matrix operations without loop.

3 ビュー (過去 30 日間)
Junaid
Junaid 2011 年 11 月 27 日
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 件のコメント
Walter Roberson
Walter Roberson 2011 年 11 月 27 日
Or is it that K and L will always be the same and the answer would go in R(K,M) ?
Junaid
Junaid 2011 年 11 月 27 日
Dear Walter, Thank for your kind consideration. I think my specification couldn't deliver full meaning.
Matrix *A* is weight Matrix. and B is the Dataset of 100 Histograms with each 10 bins. Q is the Query. For each value of bin there is already computed weight in Matrix A. So rather then Computing that again I want to retrieve that value from A.
So R(i, j) = A ( Q(i), B(i,j) )
So the resultant *R* is the matrix of Query *Q*, each col *i* of *R* is the weigth of *Q* with colum in *B*

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2011 年 11 月 27 日
I think this should work:
R = A(sub2ind(size(A), repmat(Q(:),1,size(B,2), B))
  1 件のコメント
Junaid
Junaid 2011 年 11 月 28 日
Dear Walter, Could you please tell me what if Q is an other matrix and now I want to get R_new such that each cell is the sum(minimum(R)).
Case is simple. For Q( where each col is histogram) I want to get first nearest neighbor from B.

サインインしてコメントする。

その他の回答 (1 件)

N Madani SYED
N Madani SYED 2011 年 11 月 27 日
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 件のコメント
Junaid
Junaid 2011 年 11 月 27 日
Thanks Syed. I prefer to have solution without loops as I having very big dataset.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by