# How can I visualize the data of a sparse matrix using a vector

**URL:** https://discourse.julialang.org/t/how-can-i-visualize-the-data-of-a-sparse-matrix-using-a-vector/89394
**Category:** New to Julia
**Tags:** matlab, sparse
**Created:** [October 27, 2022, 7:15pm UTC](https://discourse.julialang.org/t/how-can-i-visualize-the-data-of-a-sparse-matrix-using-a-vector/89394 "2022-10-27T19:15:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![thiagoselias](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thiagoselias/32/43916_2.png) [@thiagoselias](https://discourse.julialang.org/u/thiagoselias)
#### Post date: [October 27, 2022, 7:15pm UTC](https://discourse.julialang.org/t/how-can-i-visualize-the-data-of-a-sparse-matrix-using-a-vector/89394/1 "2022-10-27T19:15:55Z")

</div>

The way I’m doing it, the index values appear all mixed up in the code:

EX:  
v = matopen(“index.mat”);  
index= read(v, “v”);  
close(v);

x = (list[index])

 ![index](https://global.discourse-cdn.com/julialang/original/3X/5/8/5831b729630258af30f89dcda67bac40d920e602.png)

---

<div class="post-metadata">

### Author: ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)
#### Post date: [October 27, 2022, 7:45pm UTC](https://discourse.julialang.org/t/how-can-i-visualize-the-data-of-a-sparse-matrix-using-a-vector/89394/2 "2022-10-27T19:45:58Z")

</div>

How did you create `index.mat` in Matlab? Can you upload it (or a similar minimal file with the same format)? What is `list`?

But perhaps most importantly, what are you trying to do? Why don’t you just save the sparse matrix as a sparse matrix in Matlab? Example:

**Matlab** :

```nohighlight
>> M = sprandn(10000,10000,0.0001);
>> save('test.mat', 'M');

```

**Julia** :

```julia
julia> using MAT

julia> d = matread("test.mat")
Dict{String, Any} with 1 entry:
  "M" => sparse([2297, 3220, 9009, 2298, 6641, 3586, 5225, 1655, 4198, 9512 … 8606, 2691, 2919, 6280, 7576…

julia> d["M"]
10000×10000 SparseArrays.SparseMatrixCSC{Float64, Int64} with 9999 stored entries:
⢢⢄⣭⡈⡾⡅⣰⡰⡁⠪⢴⣺⣟⢶⢦⣺⠲⡰⣊⣝⣵⢲⣈⣳⠆⣇⡠⢋⡥⣃⣶⢒⠓⠣⢑⣍⣢⣳⢹⣆⡡⣳⠊⡦⣾⠭⢘⣫⣽⢾⣢⡞
⡔⣆⡒⣭⢏⡋⣹⣨⡻⢫⣡⣸⠹⢵⣾⢵⢻⢺⢬⣶⣇⣘⣙⡴⡟⡷⣯⣧⢶⢿⣎⢆⡞⣈⡝⣣⣽⢝⡝⠻⡿⠶⠂⢿⠾⢣⡟⣿⢦⡻⢜⠫
⣘⣳⢁⠰⠸⡾⣴⠷⣿⠿⠖⠑⢼⡞⡅⣣⣺⡯⢊⢺⣞⢙⢱⢾⢳⣞⣻⣺⢤⣵⣺⢪⣙⢼⡮⣾⢊⢿⣾⢥⠇⢌⠳⡟⣎⢯⣿⡟⡮⢽⡂⣻
⠘⡽⠰⡮⣷⡔⠐⠞⣿⣟⣯⣖⡫⡯⢻⣮⡌⢹⢫⢕⡎⡽⢽⣏⣑⣔⣽⣝⢭⡟⢷⡗⠻⡑⣐⢳⢷⡮⠟⣇⡷⣫⡜⣥⣶⣿⡤⣟⡢⣞⠦⡌
⢺⡃⣻⣺⣯⡟⠻⢊⢑⢫⣟⣂⣩⠿⣰⢴⢔⡿⠾⣈⢝⢎⢢⣱⢰⢹⣽⡵⡦⣾⠸⡹⠾⣖⣢⠇⡁⣴⣟⠞⣏⢵⡱⣢⣟⡵⣫⢚⡹⠞⢶⣄
⡐⡺⠜⣇⠙⡨⡶⣃⢿⣤⢫⡓⢻⡡⣝⣳⣏⡸⡻⡚⡂⣩⢷⡺⣥⡻⡅⣕⢭⣕⢔⣥⠾⢧⣟⣟⡦⣶⠣⣫⠯⣟⡝⣾⢦⣓⡕⣿⢱⠫⠜⡃
⠋⡝⡫⠤⢽⡊⠵⡘⣥⣚⡃⡪⣞⣷⣸⢃⣎⣏⢝⣘⢪⠑⡛⢷⠃⠓⣼⡿⡹⢳⣖⢯⠽⠭⢯⢾⡴⣹⡷⡯⢻⢵⣿⡃⡎⠧⢹⢪⠿⣽⣛⡶
⠽⠝⡪⠷⣪⣀⡷⢜⣗⢁⣹⠖⣨⡾⢆⣱⣝⣉⣩⡌⢺⡴⡺⠩⠖⢉⣖⣏⣧⠫⠺⢹⣓⡯⢼⡭⡤⠓⠻⣿⣵⡟⠝⣙⣴⢏⠷⡼⣣⣋⣶⠽
⠖⢵⣂⢄⣬⡟⠯⣇⠌⣯⣣⢸⢻⣊⣥⡽⠂⣥⣿⣬⢍⠏⢐⡓⣿⣹⡫⣸⣡⣥⣾⣹⢷⣾⡯⡽⠥⣩⢛⡺⢟⡻⢎⡇⣺⡗⣐⠊⡿⢙⠕⠖
⡂⢦⣪⣯⠺⣪⡋⢼⣏⡧⣬⣕⣞⡸⢫⡟⡵⣖⣞⣿⣛⣸⡓⢌⣼⢻⢆⢠⣰⡝⣮⡼⢚⠡⣇⡬⡍⢿⡪⣠⣢⢽⣒⢢⡜⡭⢾⣅⡑⢏⡲⠏
⣴⢟⢋⢾⡮⢗⡫⣮⠝⢥⡖⣝⠝⡸⣷⡼⢶⣿⢧⣹⣱⢗⢋⡖⠖⢒⢴⠴⡻⢱⡙⣘⢿⢓⢳⢷⡁⢹⡫⠝⠷⠻⢯⣿⡶⡬⣬⠚⡇⢸⣶⡇
⢸⣗⡺⢾⣾⠵⢞⣺⡒⣏⢸⡾⣝⢟⢿⢻⣇⡙⢝⡕⣯⡵⣎⡊⠍⡮⡨⡺⢻⠿⢾⣩⣋⡺⣷⡼⣹⠫⢳⢿⣏⢑⠝⣳⡿⣫⢱⢐⠂⢔⡼⡦
⢴⢩⢩⣟⡳⣮⠢⢷⠁⣨⠭⢊⣬⢰⡯⢯⣛⣐⢭⡆⡴⠱⣍⣸⠆⣴⢎⢯⣯⡑⣫⡬⣹⢹⣰⣿⡫⣪⡙⡟⠕⣧⠔⠂⣆⠝⣿⣍⣲⣶⡲⣒
⡕⣾⢠⣵⡶⢿⡌⣵⢜⣾⢗⡋⢒⢥⡺⣝⣋⣣⣀⣽⢿⣭⢸⣻⢛⢛⢶⢴⡮⣕⢢⣟⠏⣭⠯⣍⠽⣗⣮⡔⣿⢔⢾⡕⡆⣕⠗⡥⣜⢸⣗⢮
⠫⢾⡵⡗⠄⣽⣬⡽⣍⡒⢀⣍⡷⠿⡯⠯⢳⢝⢝⣯⡼⡲⢝⡋⣯⠡⡪⢭⣸⡸⡫⣾⠝⣢⡛⢾⡏⢊⠺⣴⣿⣲⣾⣧⣧⡎⡳⣭⡛⢅⣻⠒
⢮⠿⣿⠭⢯⡍⡸⢒⣝⡼⣿⠫⢾⣉⠇⠭⡷⡟⢯⡡⣖⠿⣓⢽⡹⣜⢈⣛⡗⡳⣽⣇⢇⢸⠯⣛⣄⠩⠳⣩⡚⡗⣿⣢⡭⡵⣹⡩⣟⡵⢩⢕
⣔⢓⣯⣜⣟⠭⡋⠓⢽⡳⣽⢖⣟⢡⠋⠻⣷⣗⡛⢛⢼⣞⣖⡕⣮⠳⣷⣢⣗⠤⢜⡚⢉⣿⢾⣿⣣⠩⡾⣦⡿⣶⡿⣲⣝⡫⡹⢝⡏⠺⡺⠑
⡥⣱⣏⡬⣋⡙⣸⢊⠯⢵⣱⢻⢼⡖⢒⡼⢌⣯⡳⡵⡵⣿⡙⣳⢟⡔⢊⡻⢮⢫⡿⣵⠾⡧⠮⠦⡳⣠⡎⢈⠿⢴⢯⡗⢜⡮⡧⡼⠻⠗⣪⡩
⢻⠷⡩⡧⢓⣴⡷⡙⡞⣾⠔⢷⠙⣊⣹⣘⣩⣑⠣⡵⣤⡚⣜⡷⡵⡋⡷⠵⢹⣪⢿⣚⣪⣍⣭⢲⣽⢝⣪⣷⣥⣆⢢⡮⣬⢣⠟⡵⢏⠯⠶⡥
⢻⣛⣷⣩⣎⣭⣿⢷⡜⢼⢯⡚⢧⣾⠐⠯⣉⡯⠚⡫⣆⣇⢟⠛⡖⢗⣎⠘⣿⢑⢗⠵⡺⣗⡪⢯⣦⢧⣱⣛⡻⡦⣖⢣⣋⣤⡋⡋⣚⠻⢋⠧
⢤⢿⡳⣽⠘⢛⢟⣼⣵⠳⣻⢯⣓⣸⡷⡕⡷⠳⠾⣫⢃⢭⣜⢎⠵⣵⢰⣽⢐⡹⣳⢼⡳⠢⢹⣝⠇⡾⡰⡺⣝⠉⡒⣊⣯⡎⣨⠽⣶⢞⢚⠬
⢛⢯⡾⠗⢀⠳⣫⡿⣣⡽⣴⡟⣗⢚⢛⣠⣦⣏⣺⢢⠷⣟⠖⣳⡮⠕⢧⣘⣬⣟⠒⡺⢿⣂⠭⡮⡳⠴⡿⠞⡷⠿⠕⢝⢻⣥⡹⢃⣝⡾⢽⣆
⢺⡜⡿⣧⣏⣠⣹⢽⣚⣯⡼⢿⡲⣋⢵⢐⣴⢷⢣⢴⢺⣲⢱⢜⢇⠏⣰⣚⣝⠴⣴⡟⡽⣏⡊⢖⣿⣟⣶⢧⢞⢱⢽⣐⡽⢋⣑⣶⣞⣪⢞⣖
⣋⡷⣺⣟⣏⢻⢒⢣⣙⢲⠳⡟⡼⣊⢯⡽⢗⢴⢵⣺⠛⡵⠴⢷⠿⢅⠬⠟⣝⡛⢤⠼⡱⣿⡏⣟⣍⣖⢺⣖⢣⢴⢩⢤⣛⠂⡝⡿⣶⠵⢽⡪
⠼⡇⣆⣿⠗⣡⠜⣧⢻⢻⢗⣋⣺⣍⠌⣻⣐⣯⣿⢿⣪⢦⠪⡼⠕⣞⣕⣛⠟⠝⠇⠸⢕⡬⠷⡦⡧⢥⡧⣟⠿⣛⡛⡿⠮⣹⢿⣷⠻⡮⣪⠕
⡑⠨⠦⠗⠢⡘⠿⠏⡢⣏⠼⢾⢎⢼⢷⢛⣮⠟⠓⠎⠥⠳⡄⠝⣆⠓⠾⠻⡨⣊⡸⢜⢩⠦⡱⡪⢨⠏⣗⠞⢷⠭⠪⠠⠦⠱⣬⢃⡭⢻⡯⢃

```

---

<div class="post-metadata">

### Author: ![thiagoselias](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thiagoselias/32/43916_2.png) [@thiagoselias](https://discourse.julialang.org/u/thiagoselias)
#### Post date: [October 27, 2022, 8:24pm UTC](https://discourse.julialang.org/t/how-can-i-visualize-the-data-of-a-sparse-matrix-using-a-vector/89394/3 "2022-10-27T20:24:43Z")

</div>

It is a sparse matrix from Matlab yes, I managed to solve the problem this way:

The vector with the indexes was like this:  
println(size(index))  
(6770, 1)

I did like this:  
index = reshape(index, 6770, );

x= (list[index])

 ![solucao](https://global.discourse-cdn.com/julialang/original/3X/5/e/5ebaf6e5b08a592fd978850caf7a4ae7c47e4996.png)
