Matlab's sparse matrix function

In MATLAB it’s possible to use sparse like this:

>> full(sparse([2 3 4 5; 1 2 3 4; 9 8 6 7],ones(3,1)*(1:4),1,9,9))

ans =

     1     0     0     0     0     0     0     0     0
     1     1     0     0     0     0     0     0     0
     0     1     1     0     0     0     0     0     0
     0     0     1     1     0     0     0     0     0
     0     0     0     1     0     0     0     0     0
     0     0     1     0     0     0     0     0     0
     0     0     0     1     0     0     0     0     0
     0     1     0     0     0     0     0     0     0
     1     0     0     0     0     0     0     0     0

Does julia support a similar constructor for sparse matrices? I realize I can make a loop to achieve the same effect, but I’m wondering if there is a built-in function somwhere.

Specifically, note that the input are matrices and not vectors.

Does the above code in matlab not simply iterate through the first and second input values? I.e. does their dimensionality (vector/matrix) have any bearing on the output? If not, and turning them into vectors still yields what you want, you can simply vec the first two input arguments.

sparse(vec(I), vec(J), v, m, n)
2 Likes