matlabgunzipmatlab-spm

Un-gzipping MRI Files in MATLAB


I'm learning MATLAB +SPM12 to do structural MRI analysis. To do this, I need to change the format of the files from gz to NIFTI. The guide I'm using said to use

gunzip('*.gz')
Flanker=gunzip('*.gz')
Dot indexing is not supported for variables of this type.

Error in gunzip (line 71)
       destinationIsSameAsSource = ismember(fullfile({entries.file}), fullfile(rootDir,outputDir,files));

I tried many different fixes from a google search

gunzip('sub-08.gz')
gunzip('sub-08.gz')
>> gunzip('sub-08', '*.gz')
 unzip('sub-08_T1w.nii.gz','Sub-08')`

None of these worked for various reasons sub-08 is the name of the folder trying to unzip.


Solution

  • When I give gunzip('*.gz') in a directory without any .gz files, I get the same error you are reporting ("Dot indexing is not supported for variables of this type"). This looks to be a bug in MATLAB, it should give a more informative error message.

    If you give that command in a directory that does have .gz files, it works as documented. You can also give the path to the files, for example

    gunzip('sub-08/*.gz')
    

    Or, as Mark Adler said in his answer, you can just give the name of the directory, MATLAB will find the .gz files in it automatically. This is not documented though (or if it is, it's not clear enough).

    gunzip('sub-08')
    

    Note that in these examples sub-08 is a directory under the current directory and contains files with a .gz extension.

    You can type pwd or cd to figure out what the current directory is, and cd('path') to change the current directory.

    If unsure, you can use the gunzip command with full path:

    gunzip('\home\kylee\mri\sub-08\*.gz') % (or whatever path you have of course)