Azzera filtri
Azzera filtri

Efficient way to do elementry operations on sparse matrix

4 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
Walter Roberson il 11 Mar 2021
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));

Più risposte (0)

Categorie

Scopri di più su Sparse Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by