spy doesn't work - why?
Afficher commentaires plus anciens
Hello,
I am calling spy on a sparse matrix J, within a subfunction, but the result is not displayed when I run my main.
The matrix is first created with the command sparse (m, n) as a null matrix of dimensions m*n. Then I fill it in as needed with a for, line by line, by taking subsections of the line and assigning to that subsection a vector of ones.
What could I be doing wrong that makes it so that the result of spy isn't displayed?
Basic pseudocode (the actual indexes are more complex, they are for a Jacobian pattern):
J = sparse (m, n);
for i=1:m
J(i, 5:9) = ones(5, 1);
end
spy(J)
4 commentaires
Walter Roberson
le 5 Juin 2020
By the way, I recomend that you use spalloc() instead of sparse() for that case. spalloc() permits you to indicate the number of non-zero entries you expect to have. That makes a difference because the sparse matrix must be rebuilt every time it gets "full"
Walter Roberson
le 5 Juin 2020
The code you posted works for me on its own.
You mention sub-function, so I have to wonder if you are using a shared variable improperly?
Sulaymon Eshkabilov
le 5 Juin 2020
It does work ok:
m=13; n=23;
J = sparse (m, n);
for i=1:m
J(i, 5:9) = ones(5, 1);
end
spy(J) ; shg
Clothilde Breger
le 7 Juin 2020
Réponses (0)
Catégories
En savoir plus sur Sparse Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!