# Reading .mat file in MNE

**URL:** <https://mne.discourse.group/t/reading-mat-file-in-mne/9089>\
**Category:** Support & Discussions\
**Created:** [July 19, 2024, 2:58am UTC](https://mne.discourse.group/t/reading-mat-file-in-mne/9089 "2024-07-19T02:58:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeyZzz](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/honeyzzz/32/3353_2.png) [@honeyZzz](https://mne.discourse.group/u/honeyZzz)\
**Post date:** [July 19, 2024, 2:58am UTC](https://mne.discourse.group/t/reading-mat-file-in-mne/9089/1 "2024-07-19T02:58:19Z")

</div>

```python
from scipy.io import loadmat
import mne

mat_file_name = "EEG.mat"

raw = loadmat(mat_file_name)
print(raw['EEG'])

```

dict\_keys([‘ **header** ’, ‘ **version** ’, ‘ **globals** ’, ‘EEG’])

It can be received in dictionary form. However, when reading only the EEG here, only the NumPy array is spit out. When I output the raw['EEG] shape, it comes out as (1,1). What should I do?

 ![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/9/9f12a5984aef9538d1d9d2eb5f98a33feabe0aef.png)

---

<div class="post-metadata">

**Author:** ![cbrnr](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/cbrnr/32/1409_2.png) [@cbrnr](https://mne.discourse.group/u/cbrnr)\
**Post date:** [July 19, 2024, 6:51am UTC](https://mne.discourse.group/t/reading-mat-file-in-mne/9089/2 "2024-07-19T06:51:15Z")

</div>

Usually, loading the file with `simplify_cells=True` already makes the structure a bit less complex. Can you try and see if this helps in your case?

---

<div class="post-metadata">

**Author:** ![honeyZzz](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/honeyzzz/32/3353_2.png) [@honeyZzz](https://mne.discourse.group/u/honeyZzz)\
**Post date:** [July 20, 2024, 6:32am UTC](https://mne.discourse.group/t/reading-mat-file-in-mne/9089/3 "2024-07-20T06:32:58Z")

</div>

notimplementederror: please use hdf reader for matlab v7.3 files, e.g. h5py

```python
data = {}
f = h5.File('test.mat')
for k, v in f.items():
    data[k] = np.array(v)

print(data.shape)

```

![image](https://global.discourse-cdn.com/free1/uploads/mne/original/2X/0/0a1756c4f0a58878c9b01cfa970359ea71ef0854.png)

In this case, need to read it with h5py, but what should do if only measured items exist in the index and cannot see the values ​​of the measured items?

I think it should have the shape (41, n).

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [July 20, 2024, 4:46pm UTC](https://mne.discourse.group/t/reading-mat-file-in-mne/9089/4 "2024-07-20T16:46:22Z")

</div>

> [@honeyZzz](#):
>
> ```python
> data = {}
> 
> ```

You created a dictionary with 41 keys. Instead, you probably want a list and then use `np.vstack` (or was it `hstack`?) or something. Not sure why `data.shape` even works for you, this actually should raise an exception.

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [July 27, 2024, 4:46pm UTC](https://mne.discourse.group/t/reading-mat-file-in-mne/9089/5 "2024-07-27T16:46:43Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
