open-discussion > Converting .mat files to Nifty
Showing 1-4 of 4 posts
Results per page:
Dec 13, 2018  05:12 AM | Carlotta Fabris
Converting .mat files to Nifty
Hi everyone!

I have some .mat files that have been preprocessed. The people who did it told me they were preprocessed with BrainVoyager, but since they are .mat files I think they actually usede SPM.

Yesterday I wrote to the BrainVoyager support and they told me that probably NITRC would have benn helpful in the conversion.

Do you know how I can use this software to convert the files I have to nifty? When I open them in Matlab the only thing I see are cells containing double values and I wasn't expecting this giving that they should have been preprocessed using SPM.

I really don't know what to do, can you help me?

Thank you a lot,
Dec 14, 2018  10:12 AM | Zeus Gracia - Universidad Nacional Autónoma de México
RE: Converting .mat files to Nifty
Hi Carlotta,

I've been losing my practise with matlab, but you can do it with R (and this one is free). You will need to install "R.matlab" and "RNifti" packages first. Then follow this code:

#Import .mat to R object
mat <- readMat("/path/file.mat")
# This imports a list object, but the first element of the list [[1]] has the numeric data
vol <- mat[[1]]

#Then export that volume
nii <- updateNifti(vol)

It worked for me, hope it works for you too.
Dec 14, 2018  11:12 AM | Carlotta Fabris
RE: Converting .mat files to Nifty
Thank you a lot for the answer!

I will keep you updated on my progresses.

Thank you again,
Dec 17, 2018  01:12 AM | Allen Waggoner
RE: Converting .mat files to Nifty
Hi Carlotta,

Since R2017b, Matlab has included the routine niftiwrite

So if your mat file also contains the header info, you should be able to easily write the nifti file. 

If you have an older version of Matlab you could try this

Also, Freesurfer (  comes with a Matlab library that includes a routine for writing nifti files.