Efficient way to do elementry operations on sparse matrix

조회 수: 1 (최근 30일)
Orr Streicher
Orr Streicher 2021년 3월 11일
댓글: Orr Streicher 2021년 3월 11일
Hi,
I am working with sparse matrices and i wonder if there is an efficient way to scan the elements of this kind of matrices and to perform some elemtry operations on them.
To be more specific, I have a sparse matrix W with elements w_ij. I want to create another sparse matrix Q in the same size of W where its elemets are q_ij=(w_ij^2)/[(w_ii^2)(w_jj^2)]. (i know that the diagonal elements of W are not zeros)
I wonder if there is an option to scan and perform this operation only on the exsit elements of W (and not to scan all its elements since most of them are zeros )
Thanks

채택된 답변

Walter Roberson
Walter Roberson 2021년 3월 11일
You can use the three-output form of find():
[row, column, value] = find(W);
diags = full(diag(W)); %we are told diagonals are non-zero so this is dense
Q = sparse(row, column, value.^2 ./ (diags(row).^2 .* diag(column).^2));

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by