# mne\_raw2mat

**URL:** <https://mne.discourse.group/t/mne-raw2mat/559>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [March 29, 2013, 10:15pm UTC](https://mne.discourse.group/t/mne-raw2mat/559 "2013-03-29T22:15:30Z")\
**Posts on this page:** 2\
**Page:** 1

<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:** [March 29, 2013, 10:15pm UTC](https://mne.discourse.group/t/mne-raw2mat/559/1 "2013-03-29T22:15:30Z")

</div>

Hi,

I was wondering if there is any means of writing a FIF file from the data  
structures output by the mne\_raw2mat command?

Otherwise, how could I replace the recordings stored in a RAW data file  
(.fif) with those stored within a Matlab variable?

Thanks for your help,

--Gabriel

---

<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:** [March 29, 2013, 10:26pm UTC](https://mne.discourse.group/t/mne-raw2mat/559/2 "2013-03-29T22:26:36Z")

</div>

Hey Gabriel,

I have had to do this in MATLAB due to a digitization error (where it was  
easier for me to swap data than swap sensor information / digitization). I  
basically hacked my own M-file based on the mne\_ex\_read\_write\_raw.m in the  
mne MATLAB toolbox, which should have all the functions you need. I'm not  
sure if there's a more principled way of doing it using the MATLAB  
functions currently -- it's less trivial to implement than it seems at  
first because the raw file contains much more information (sensor types,  
digitization info, etc.) than just the raw data samples. But if you stick  
to the example file, you should be okay (and can of course check using  
mne\_browse\_raw).

You could also consider using mne-python, where it would be the following:

import mne  
raw = mne.fiff.Raw('my\_raw.fif', preload=True)  
raw.\_data[my\_channel\_index] = my\_new\_data  
raw.save('my\_fixed\_raw.fif')  
raw.plot() # if you wanted to visualize the data after changing it

I can you send the M-file I used if you want, but it's likely less useful  
than the example m-file included with MNE.

Cheers,  
Eric
