フィルターのクリア

Sparse matrix and savings

4 ビュー (過去 30 日間)
D_coder
D_coder 2018 年 8 月 14 日
コメント済み: Walter Roberson 2018 年 9 月 14 日
I have a complex matrix which has non zero values only in specific region of the matrix. And most of the remaining part is equal to zero(see the image).The size of the matrix is m x n where m >>>> n eg. 4096 x 256 and I want to carry out element by element multiplication with another complex matrix of same size that has a specific pattern.But here's the problem since the complex matrix has majority of its elements zero (some real some imaginary and sometimes both)I want to store it in sparse form and multiply only the elements which are non zero with that of the pattern_matrix at those positions of non-zero elements in the complex sparse matrix. How do I do it efficiently and save complex multiplications without degradation in quality?
PSEUDO CODE
for 1:value
while(condition is true)
Sparse_Matrix = Sparse_Matrix.*Pattern_Matrix(value)
Another_Matrix(count,:) = sum(Sparse_Matrix)
Increment count
end of while loop
Some operations;
end of For loop
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 9 月 14 日
Please do not close questions that have an answer.

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

採用された回答

James Tursa
James Tursa 2018 年 8 月 14 日
編集済み: James Tursa 2018 年 8 月 14 日
I don't fully understand your pseudo code, particularly your use of value when indexing into Pattern_Matrix(value). If you just want to do element-by-element multiplication with only those non-zero element spots in the sparse matrix, then you can do this:
g = Sparse_Matrix ~= 0; % index spots where you want to do the multipies
Sparse_Matrix(g) = Sparse_Matrix(g) .* Pattern_Matrix(g); % do the multiplies in only those spots
You could also just do it directly as follows (probably faster than above method), but NaN's and Inf's in the non-zero spots will propagate:
Sparse_Matrix = Sparse_Matrix .* Pattern_Matrix;
  9 件のコメント
D_coder
D_coder 2018 年 8 月 18 日
My main concern is to save the multiplications. For the time being I am not concerned with the execution time,
Walter Roberson
Walter Roberson 2018 年 8 月 23 日
編集済み: Walter Roberson 2018 年 8 月 23 日
Remember to detect the cases where one or both operands to the potential multiplication are integers in which case you can convert the multiplications to repeated additions. And remember to put in a cache to detect multiplications that have already been done so you can retrieve the result instead of calculating it.
Since, after all, all you care about is the absolute number of multiplications, not about execution time or memory usage.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by