The sparse function in MATLAB does the following:

S = sparse(i,j,v) generates a sparse matrix S from the triplets i, j, and v such that S(i(k),j(k)) = v(k). The max(i)-by-max(j) output matrix has space allotted for length(v) nonzero elements. sparse adds together elements in v that have duplicate subscripts in i and j. If the inputs i, j, and v are vectors or matrices, they must have the same number of elements. Alternatively, the argument v and/or one of the arguments i or j can be scalars.

I would like to have a fairly equivalent function in Mathematica. Has anyone tried to do this beforehand?

  • 1
    $\begingroup$ Isn't SparseArray close enough? $\endgroup$ – Kuba May 26 '16 at 9:53
  • $\begingroup$ I'm not sure. What questions me is the different output of the Matlab function. $\endgroup$ – Mirko Aveta May 26 '16 at 10:35
  • $\begingroup$ The output in matlab. It's something different, perhaps because it is compressed. $\endgroup$ – Mirko Aveta May 26 '16 at 10:55
  • $\begingroup$ I think the difference lays in the compression of the memory. $\endgroup$ – Mirko Aveta May 26 '16 at 11:01
  • 1
    $\begingroup$ Then ask that question :) It is possible that there is someone around who knows both but this is MMA related site so you will gather more attention bringing info about Matlab side yourself. Moreover a motiviation would be good, e.g. specific example which Matlab handles way better than MMA and you want to know why. $\endgroup$ – Kuba May 26 '16 at 11:12

Mathematica has sparse arrays not just sparse matrices:

Here are links to some tutorials:

The ability to use high-dimensional sparse array sometimes is very useful. (E.g. see "Markov chains n-gram model implementation".)

Most competitors of Mathematica support only sparse matrices.

Yifan Hu and Robert Knapp were the original designers of the functionality. I mention Yifan because before moving to Wolfram Research he worked with some of the originators and creators of the sparse matrices field (like John Reid).

  • $\begingroup$ Slightly off-topic: if memory serves, wasn't the graph-plotting stuff an outgrowth of their work on sparse matrices? $\endgroup$ – J. M. will be back soon May 26 '16 at 12:29
  • $\begingroup$ @J.M. Yes, I would say so. Yifan designed and implemented GraphPlot and he was using it to demonstrate the origins of some of the matrices from Matrix Market. $\endgroup$ – Anton Antonov May 26 '16 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.