da 3m0o » 29/04/2021, 19:56
Digitando "help sparse" sul terminale mi dice questo: ma non capisco come cavolo fare i due vettori di cui ho bisogno, perché non capisco come dichiararli onestamente.
sparse Create sparse matrix.
S = sparse(X) converts a sparse or full matrix to sparse form by squeezing
out any zero elements.
S = sparse(i,j,s,m,n,nzmax) uses vectors i, j, and s to generate an
m-by-n sparse matrix such that S(i(k),j(k)) = s(k), with space
allocated for nzmax nonzeros. Vectors i, j, and s are all the same
length. Any elements of s that are zero are ignored, along with the
corresponding values of i and j. Any elements of s that have duplicate
values of i and j are added together. The argument s and one of the
arguments i or j may be scalars, in which case the scalars are expanded
so that the first three arguments all have the same length.
S = sparse(i,j,s,m,n) where nzmax = length(s).
S = sparse(i,j,s) where m = max(i) and n = max(j).
S = sparse(m,n) abbreviates sparse([],[],[],m,n,0). This
generates the ultimate sparse matrix, an m-by-n all zero matrix.
For example, this dissects and then reassembles a sparse matrix:
[i,j,s] = find(S);
[m,n] = size(S);
S = sparse(i,j,s,m,n);
So does this, if the last row and column have nonzero entries:
[i,j,s] = find(S);
S = sparse(i,j,s);