1

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.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • How do I pass the names? I looked at the resource and it seems to say can just put down the folder name and will pull out files to be unzipped. – Kylee Miller Jun 28 '23 at 19:21

2 Answers2

1

If sub-08 is a folder that contains gzip files, then use res = gunzip('sub-08') to extract all of them, including those in sub-sub-folders. res will be a list of the filenames of the uncompressed files.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • The documentation does not support this, but I tried it and it works. – Cris Luengo Jun 28 '23 at 19:18
  • I didn't know the answer until I looked at the documention! It says exactly this. https://www.mathworks.com/help/matlab/ref/gunzip.html – Mark Adler Jun 28 '23 at 19:29
  • It says "gzipfilenames — Names of the GNU zip files to extract from, specified as a character vector, a cell array of character vectors, or a string array. File names must include a path relative to the current folder or an absolute path." It doesn't say "names of directories under which to find gzip files". – Cris Luengo Jun 28 '23 at 19:43
  • You have to read the whole thing. "`gunzip(gzipfilenames)` extracts the archived contents of each file _in_ `gzipfilenames` to the folder containing `gzipfilenames`", and "`gunzip` recursively extracts the content in _folders_". (My emphases.) – Mark Adler Jun 28 '23 at 20:10
0

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)
Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
  • 1
    Note that if there are also *.gz files in a sub-directory of `sub-08`, but you only want to decompress the ones at the top level of `sub-08`, then you would need to use `gunzip('sub-08/*.gz')`. Otherwise you can use `gunzip('sub-08')`. – Mark Adler Jun 28 '23 at 20:25