# Plotting .mat data

**URL:** <https://discourse.julialang.org/t/plotting-mat-data/19600>\
**Category:** Visualization\
**Tags:** matlab\
**Created:** [January 13, 2019, 10:58pm UTC](https://discourse.julialang.org/t/plotting-mat-data/19600 "2019-01-13T22:58:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![svpillai](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@svpillai](https://discourse.julialang.org/u/svpillai)\
**Post date:** [January 13, 2019, 10:58pm UTC](https://discourse.julialang.org/t/plotting-mat-data/19600/1 "2019-01-13T22:58:16Z")

</div>

I have a .mat file that I’ve opened using Matlab.jl with read\_matfile(filename) (is there a better way/command to load .mat data on to Julia?), and I need to plot certain rows of the .mat file. How do I do so? using Plots/PyPlot preferably. Also, would it be possible to plot data from the .mat file and a .jld2 file in the same graph?

---

<div class="post-metadata">

**Author:** ![affans](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/affans/32/11911_2.png) [@affans](https://discourse.julialang.org/u/affans)\
**Post date:** [January 13, 2019, 11:01pm UTC](https://discourse.julialang.org/t/plotting-mat-data/19600/2 "2019-01-13T23:01:59Z")

</div>

Try [https://github.com/JuliaInterop/MATLAB.jl](https://github.com/JuliaInterop/MATLAB.jl)

In particular, the reading/writing MAT files: [GitHub - JuliaInterop/MATLAB.jl: Calling MATLAB in Julia through MATLAB Engine](https://github.com/JuliaInterop/MATLAB.jl#readwrite-mat-files)

---

<div class="post-metadata">

**Author:** ![jebej](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jebej/32/1784_2.png) [@jebej](https://discourse.julialang.org/u/jebej)\
**Post date:** [January 13, 2019, 11:06pm UTC](https://discourse.julialang.org/t/plotting-mat-data/19600/3 "2019-01-13T23:06:30Z")

</div>

MATLAB.jl requires MATLAB. For simply reading mat files, you could use [MAT.jl](https://github.com/JuliaIO/MAT.jl), though it might be broken on 1.0 still.

---

<div class="post-metadata">

**Author:** ![svpillai](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@svpillai](https://discourse.julialang.org/u/svpillai)\
**Post date:** [January 13, 2019, 11:10pm UTC](https://discourse.julialang.org/t/plotting-mat-data/19600/4 "2019-01-13T23:10:50Z")

</div>

I’ve already opened the file on Julia using Matlab.jl with the read\_matfile command (I have Matlab installed, but need to do the plotting specifically on Julia; I’m using v1.0.2). The Github Matlab.jl doesn’t mention plotting from .mat specifically, and I also don’t particularly know how to plot from both the .mat file and the .jld2 file on the same graph.

---

<div class="post-metadata">

**Author:** ![jebej](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jebej/32/1784_2.png) [@jebej](https://discourse.julialang.org/u/jebej)\
**Post date:** [January 13, 2019, 11:16pm UTC](https://discourse.julialang.org/t/plotting-mat-data/19600/5 "2019-01-13T23:16:04Z")

</div>

If your data has been imported already, you need a plotting package to plot it. Here are some references to get you started:  
[https://julialang.org/downloads/plotting.html](https://julialang.org/downloads/plotting.html)  
[https://en.wikibooks.org/wiki/Introducing\_Julia/Plotting](https://en.wikibooks.org/wiki/Introducing_Julia/Plotting)

---

<div class="post-metadata">

**Author:** ![svpillai](https://avatars.discourse-cdn.com/v4/letter/s/90db22/32.png) [@svpillai](https://discourse.julialang.org/u/svpillai)\
**Post date:** [January 14, 2019, 9:14am UTC](https://discourse.julialang.org/t/plotting-mat-data/19600/6 "2019-01-14T09:14:19Z")

</div>

How do I specify in my code specifically one row to plot out of the entire dataset? p = plot(file, x=[:1]) just plots the entire 150x40 matrix in the file.

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [January 14, 2019, 10:18am UTC](https://discourse.julialang.org/t/plotting-mat-data/19600/7 "2019-01-14T10:18:50Z")

</div>

First load the mat file with eg.

```julia
using MAT
fh = matopen("MatFile.mat")           
    println("\nVariables in mat file: ",names(fh))
    (A,B) = read(fh,"A","B")                                
close(fh) 

```

Then, (assuming `A` is a matrix), you can plot column 2 and 3 by  
`plot(A[:,2:3])`.

See the Plots.jl or PyPlot.jl documentation for more details.
