Borrar filtros
Borrar filtros

Efficient way to do elementry operations on sparse matrix

4 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 11 de Mzo. de 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));

Más respuestas (0)

Categorías

Más información sobre Sparse Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by