how to do the sparse indexing
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello all, I want to do the following sparse array index. Here, P is a 3-dimansional cell matrix, because the matrix is very large,I cann't use zeros function to define matrix A. But the following code showed 'the sparse indexing expression is likely to be slow.' Do you have any idea to solve that? Thank you !
A=sparse(S,S)
for s=1:S
A(s,:)=P{u(s)}(s,:);
end
0 commentaires
Réponses (1)
John D'Errico
le 14 Déc 2016
Hmm. You created A as sparse, and all zero. Then you index into A1, which appears to be undefined. I'll assume that you simply cannot type, and meant A there also.
Instead, you need to learn to actually use sparse, instead of trying to stuff elements into a sparse matrix one at a time. READ THE HELP FOR SPARSE! My re-writing that help for you to read cannot possibly be more efficient than you simply reading the help yourself.
help sparse
doc sparse
As far as improving the code you have written that uses a cell array P of completely unknown shape and size, and some completely unknown function of variable u, you probably need to learn to use tools like cellfun, cat, cell2mat, etc. Then make one call to sparse at the end. But I cannot read your mind about things you won't bother to tell us.
0 commentaires
Voir également
Catégories
En savoir plus sur Sparse Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!