Finding and using sparse matrix indices

9 ビュー (過去 30 日間)
Christopher
Christopher 2014 年 2 月 24 日
回答済み: Iain 2014 年 2 月 24 日
I have the sparse matrix array L=
(36,67) 1
(39,70) 1
(42,73) 1
(45,76) 1
(48,79) 1
(51,82) 1
(54,85) 1
and a large matrix M. I need to use the index coordinates of each of the elements in L, offset the coordinates by some amount, find the element in matrix M having those coordinates, and multiply the result. The operation must be vectorized.
A pseudocode might look like:
out=L*M(Lrow+5,Lrow+Lcolumn-15);
where Lrow is the row in L and parentheses are the matrix coordinates in M, determined for each element in L.
Thanks.

採用された回答

Iain
Iain 2014 年 2 月 24 日
If L is the same size as M:
idx = find(L);
Move the idx around by adding 1 (moves it down one), or by adding the number of columns (moves it right one) - Just be aware that if you move them down far enough, they'll move right.
idx = idx + 1 + cols; % right AND down one.
the_values = M(idx);

その他の回答 (0 件)

カテゴリ

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