save to mat file

External Email - Use Caution

Hello,

I am trying to convert the forward data from fiff to .mat, I have the below error when I am saving:

import os.path as op
import scipy.io as sio
import numpy as np
import mne

data_path = mne.datasets.opm.data_path()
subject = 'OPM_sample'
subjects_dir = op.join(data_path, 'subjects')
raw_fname = op.join(data_path, 'MEG', 'OPM', 'OPM_SEF_raw.fif')
bem_fname = op.join(subjects_dir, subject, 'bem',
                    subject + '-5120-5120-5120-bem-sol.fif')
fwd_fname = op.join(data_path, 'MEG', 'OPM', 'OPM_sample-fwd.fif')
coil_def_fname = op.join(data_path, 'MEG', 'OPM', 'coil_def.dat')
fwd = mne.read_forward_solution(fwd_fname)
sio.savemat('fwd.mat', {'fwd':fwd})

  File "C:\Users\zahransa\anaconda3\lib\site-packages\scipy\io\matlab\mio5.py", line 611, in write
    % (arr, type(arr)))

TypeError: Could not convert None (type <class 'NoneType'>) to array

Thanks for your suggestion

Best regards
Saeed

External Email - Use Caution

Dear Saeed,

fwd is a complex data structure. Not a plain array that you can save in .mat.

if you want the fwd leadfiled matrix

sio.savemat('fwd.mat', {'fwd':fwd['sol']['data']})

HTH
Alex