# What is the equivalence to Matlab code "sparse(1:3, \[1 3 5\], \[11 12 13\])" in Julia

**URL:** <https://discourse.julialang.org/t/what-is-the-equivalence-to-matlab-code-sparse-1-3-1-3-5-11-12-13-in-julia/81537>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 23, 2022, 8:26pm UTC](https://discourse.julialang.org/t/what-is-the-equivalence-to-matlab-code-sparse-1-3-1-3-5-11-12-13-in-julia/81537 "2022-05-23T20:26:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [May 23, 2022, 8:26pm UTC](https://discourse.julialang.org/t/what-is-the-equivalence-to-matlab-code-sparse-1-3-1-3-5-11-12-13-in-julia/81537/1 "2022-05-23T20:26:21Z")

</div>

What is equivalent to the below Matlab code in Julia. Which creates a sparse matrix of `1:3` rows and fills the elements in columns `[1 3 5]` (corresponding to rows 1:3) by `[11 12 13]`

```matlab
>> sparse(1:3, [1 3 5], [11 12 13])

ans =

   (1,1) 11
   (2,3) 12
   (3,5) 13

```

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [May 23, 2022, 8:32pm UTC](https://discourse.julialang.org/t/what-is-the-equivalence-to-matlab-code-sparse-1-3-1-3-5-11-12-13-in-julia/81537/2 "2022-05-23T20:32:17Z")

</div>

have you tried to google or use the build-in help mode?

```julia
>help sparse
  sparse(I, J, V,[m, n, combine])

  Create a sparse matrix S of dimensions m x n such that S[I[k], J[k]] = V[k]. The combine function is used to combine duplicates. If m and n are not specified, they are set to maximum(I) and
  maximum(J) respectively.

```

```julia
julia> sparse(1:3, [1,3,5], [11,12,13])
3×5 SparseMatrixCSC{Int64, Int64} with 3 stored entries:
 11 ⋅ ⋅ ⋅ ⋅
  ⋅ ⋅ 12 ⋅ ⋅
  ⋅ ⋅ ⋅ ⋅ 13

```

---

<div class="post-metadata">

**Author:** ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)\
**Post date:** [May 23, 2022, 8:34pm UTC](https://discourse.julialang.org/t/what-is-the-equivalence-to-matlab-code-sparse-1-3-1-3-5-11-12-13-in-julia/81537/3 "2022-05-23T20:34:51Z")

</div>

Thank you very much!
