[Solved] How can do I make a sparse matrix using cell arrays in MATLAB?


By the information in the question :

In vector cell arrays it is usually the first vector used as a sparse
matrix dimension

The second element is a scalar specifying the default value of the
sparse matrix

The other vectors are used to specify the location and the value of
the element in the sparse matrix , i.e. [i, j, x] where i,j is the location
in the matrix and x is the value of the element.

So the program is simply :

function matrix=sparse2matrix(cellvec);

matrix=zeros(cellvec{1})+cellvec{2};

for i=3:length(cellvec)

      matrix(cellvec{i}(1,1),cellvec{i}(1,2))=cellvec{i}(3);

end

0

solved How can do I make a sparse matrix using cell arrays in MATLAB?