MNE in Matlab

Thank you, Sheraz.

To assemble the inv operator I had a look at mne_ex_compute_inverse and
there are a number of arguments (e.g., setno [data set number], lambda2,
sDPM, sLORETA), that complicate things since I don't know where to get
these values from or how to find them.

Ade

Some default values

setno = 1; %(Event code that you put in your stimulus program)
nave = -1; %(Number of averages, -1 will read it from -ave.fif file)
dSPM = true; % (Convert the inverse map to Statistical score wrt to
baseline noise covirance)
lambda2 = 1/9 %(Default regularization parameter)

HTH

Sheraz

Thank you. I still got the error that the number of arguments was wrong. It
seem to run adding just '1' for the argument "dSPM"). However, I get the
following error:

Error using fiff_read_evoked (line 83)

Could not find processed data

Error in mne_ex_compute_inverse (line 53)

data = fiff_read_evoked(fname_data,setno);

I noticed I have no -ave.fif file in the set of files computed with MNE
python.

Maybe that is the source of the issue?

Ade

On the mne-python side you need to convert your data into Evoked object,
using mne python class
https://martinos.org/mne/dev/generated/mne.Evoked.html
And then you can use .save function exposed by Evoked object to save it
into -ave.fif file.

Please open issue on GitHub and share your pipeline with some sample data

Sheraz

Thanks again, Sheraz.

I am confused because my original question was how to compute the source
data (in Matlab) if I already have the inverse solution. You mentioned I
could use mne_read_inverse_operator.m but I should assemble it and referred
me to the function mne_ex_compute_inverse.m. But this function asks for the
_ave-fif file, which I don't have, and seems to me that it is rather to
compute the inverse solution, which I already have ("% An example on how to
compute a L2-norm inverse solution, and not to create the source estimates.

I had a look at how the source data is computed in Python and it just uses
"read_inverse_operator" to read the inv solution, and "apply_inverse_raw"
for the source estimation (which is what I aim to do in Matlab), which
doesn't need the _ave.fif file.

Maybe I am misunderstanding something?
Thank you,
Ade

Hi Adela,

You can do the same in Matlab, Tomorrow, I will create a small matlab gist
for you, in which, you input raw and inv file, and it outputs source
estimates, like apply_inverse_raw in mne-python.

Best

Sheraz

Thank you very much, Sheraz, you are very kind to do so.
So is there at the moment no way to do this in Matlab as per the Matlab set
of functions provided by MNE?
Ade

Please find gist at

https://gist.github.com/SherazKhan/866dd62722b46a39ec6f8ce3f1806a68

fname_inv = 'sample_audvis-meg-oct-6-meg-fixed-inv.fif'
fname_raw = 'sample_audvis_tsss.fif'
sol = apply_inverse_raw(fname_raw,fname_inv)

As you can see, it is done using mne-matlab function.

The wisdom behind not assembling inverse operator in the inverse file, is
to make it general, so that same inverse operator can be applied to raw or
ave file.

HTH

Best

Sheraz

Thank you! This is great. I will have a look soon.

Hi again,

Just my last question regarding this issue: you mentioned that "The wisdom
behind not assembling inverse operator in the inverse file, is to make it
general, so that same inverse operator can be applied to raw or
ave file.". Could you expand a bit on this? How can I control how to
assemble the inv operator as "general"?

Thanks,
Ade

The key in assembling inverse is to control regularization, which is
normally the factor of number of trials, since raw data is just single
trial more regularization is needed compare to evoked.
Regularization provide stability to the inverse operator at the expense of
sptial resolution.

Hope this help

Sheraz