# Reading .mat file matrices

**URL:** https://discourse.julialang.org/t/reading-mat-file-matrices/15405
**Category:** New to Julia
**Created:** [September 24, 2018, 1:24am UTC](https://discourse.julialang.org/t/reading-mat-file-matrices/15405 "2018-09-24T01:24:03Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Inalvis\_Alvarez](https://avatars.discourse-cdn.com/v4/letter/i/839c29/32.png) [@Inalvis\_Alvarez](https://discourse.julialang.org/u/Inalvis_Alvarez)
#### Post date: [September 24, 2018, 1:24am UTC](https://discourse.julialang.org/t/reading-mat-file-matrices/15405/1 "2018-09-24T01:24:03Z")

</div>

I’m trying to solve an optimization program but have all the matrices as matlab files. I was able to import those that have numbers within the matrix but those with variables give the following error:  
BoundsError: attempt to access 15-element Array{Type,1} at index [17]  
in read at MAT\src\MAT\_v5.jl:352  
in read\_matrix at MAT\src\MAT\_v5.jl:302  
in read\_matrix at MAT\src\MAT\_v5.jl:331

The code used is the following:  
file = matopen(“x.mat”)  
FA = read(file, “x”)  
close(file)

Does anyone know how to address this issue?  
Thank you

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [September 24, 2018, 1:42am UTC](https://discourse.julialang.org/t/reading-mat-file-matrices/15405/2 "2018-09-24T01:42:47Z")

</div>

That error usually means there’s some values in the mat file that’s not supported (at least that’s what I got in [this](https://github.com/JuliaIO/MAT.jl/issues/53) case and from a rough reading of the code I can imagine it happen for other unsupported objects too).

I fixed the issue by just not saving that object in the mat file. (It was put in there by someone else a long time ago and we don’t actually need it anyway…) You can check all the fields in the mat file to verify if this is an issue for you.

---

<div class="post-metadata">

### Author: ![Inalvis\_Alvarez](https://avatars.discourse-cdn.com/v4/letter/i/839c29/32.png) [@Inalvis\_Alvarez](https://discourse.julialang.org/u/Inalvis_Alvarez)
#### Post date: [September 26, 2018, 1:17am UTC](https://discourse.julialang.org/t/reading-mat-file-matrices/15405/3 "2018-09-26T01:17:39Z")

</div>

Turns out there were some spaces and brackets in the matrix. Thank you

---

<div class="post-metadata">

### Author: ![Graham\_W\_Griffiths](https://avatars.discourse-cdn.com/v4/letter/g/b77776/32.png) [@Graham\_W\_Griffiths](https://discourse.julialang.org/u/Graham_W_Griffiths)
#### Post date: [February 19, 2019, 2:55pm UTC](https://discourse.julialang.org/t/reading-mat-file-matrices/15405/4 "2019-02-19T14:55:52Z")

</div>

## I am just starting to learn Julia and trying to run the following code, adapted from above:

## using MAT fileIn = matopen(“complexDomainData.mat”) dset = read(fileIn) close(fileIn)

but I get the error:

LoadError: File “complexDomainData.mat” does not exist and create was not specified

The file was created in Matlab and opens OK in Matlab. I can also import it into R.

Any help appreciated

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [February 19, 2019, 2:58pm UTC](https://discourse.julialang.org/t/reading-mat-file-matrices/15405/5 "2019-02-19T14:58:45Z")

</div>

Does the file exist?

---

<div class="post-metadata">

### Author: ![Graham\_W\_Griffiths](https://avatars.discourse-cdn.com/v4/letter/g/b77776/32.png) [@Graham\_W\_Griffiths](https://discourse.julialang.org/u/Graham_W_Griffiths)
#### Post date: [February 19, 2019, 2:59pm UTC](https://discourse.julialang.org/t/reading-mat-file-matrices/15405/6 "2019-02-19T14:59:42Z")

</div>

Yes, the file was created in Matlab and opens OK in Matlab. I can also import it into R. It just contains some numeric arrays.

---

<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: [February 19, 2019, 3:29pm UTC](https://discourse.julialang.org/t/reading-mat-file-matrices/15405/7 "2019-02-19T15:29:33Z")

</div>

Either:  
(1) Go to the folder where the file is (`cd("ToWhereTheFileIs)`) and then try again to read it, or  
(2) Supply the full path/filename to `matopen`

---

<div class="post-metadata">

### Author: ![Graham\_W\_Griffiths](https://avatars.discourse-cdn.com/v4/letter/g/b77776/32.png) [@Graham\_W\_Griffiths](https://discourse.julialang.org/u/Graham_W_Griffiths)
#### Post date: [February 19, 2019, 3:53pm UTC](https://discourse.julialang.org/t/reading-mat-file-matrices/15405/8 "2019-02-19T15:53:27Z")

</div>

Many thanks, the full path solved the problem.
