spm_get, spm_select, and char

1 min read

The mostly used functions I use in SPM is spm_get (for spm2) and spm_select (spm5 and 8).  These two functions are used to get files (usually image files). Frankly speaking I like spm_get much better as it’s intuitive and easy to use. Here is how to use them:

Select some image files interactively (a window pops up and users select),

    p = spm_get([],'*.img','Select the image(s)');
    p = spm_select([0:200],'IMAGE','Select the image(s)');

Select some files automatically,

    p = spm_get('files', pwd, '*.img');
    p = spm_select('list', pwd, '.*img');

The filter in spm_select is different from that in spm_get. In spm_get, the filter is traditional linux/windows file filters such as *.img, ???.hdr etc. In spm_select the filters are regular expressions. For example, to get all files starting with I and end with .img, you put something like ‘^I.*\.img’.

To concatenate two file lists vertically, you can use char function:

    p = char(p1, p2);

char will automatically fill blanks so p1 and p2 are of the same columns to be vertically concatenated.

Below are more examples of spm_get and spm_select:

% select some files interactively and save the file names into a variable P
P = spm_get
% select 6 (not 5, not 7, exactly 6) files interactively
P = spm_get(6)
% select 2 to 4 files interactively
P = spm_get([2:4])
% select 0 to 8 files interactively
P = spm_get([0:8])
% automatically get all imaging files in the directory c:\abc
P = spm_get('Files', 'c:\abc', '*.img')
% automatically get all mat files starting with e in the current working directory
P = spm_get('Files', pwd, 'e*.mat')
% automatically get the mat files in the directory c:\abc which satisfy the following condition: the file names end with f and another two characters. Pay attention to the usage of * and ?
P = spm_get('Files', 'c:\abc', '*f??.mat')
% select some (<200) folders interactively. Now you see, negative numbers means to select folder instead of files
P = spm_get([-200:0])

% select some files interactively and save the file names into a variable P
P = spm_select
% select 6 (not 5, not 7, exactly 6) files interactively
P = spm_select(6)
% select 2 to 4 files interactively
P = spm_select([2 4])
% automatically get all imaging files in the directory c:\abc. Files are saved in P and directories are saved in dirs
[P, dirs] = spm_select('list', 'c:\abc', 'img')


Receive email notification via email
Don't want to miss new papers in your field? Check out Stork we developed:

fNIRS Journal Club 视频 浙江大学刘涛研究员

浙江大学刘涛研究员 浙江大学的刘涛研究员,博士生导师, 为大家讲解一篇商科领域的EEG文章: Samuel B. Barnett, and Moran Cerf (2017), “A ticket for your thoughts: Method for predicting content recall and sales using neural...
Xu Cui
10 sec read

fNIRS Journal Club 通知 2020/6/28, 11am

北京时间2020年6月28日周日上午11点,浙江大学的刘涛研究员,博士生导师, 将为大家讲解一篇商科领域的EEG文章。文章中提出的方法对近红外领域有很好的借鉴作用。同时,刘老师会结合他最近的一篇文章,讲一下类似的时间窗口方法可以帮助我们了解什么额外信息。 时间: 北京时间2020年6月28日周日上午11点 地点: https://zoom.com房间号: 876 6491 1732密码: 819151 他要讲的文献如下: Samuel B. Barnett, and Moran Cerf (2017), “A ticket for your thoughts: Method...
Xu Cui
50 sec read

NeuroSync 2020 线上国际研讨会

北京时间2020-06-13,NeuroSync 2020 线上国际研讨会将会通过Zoom和小鹅通召开,具体日程见下。欢迎大家参加。
Xu Cui
0 sec read

2 Replies to “spm_get, spm_select, and char”

  1. Hi Dear Xu,
    I want to work with MNET Toolbox in MATLAB. When I click studyList for importing data, I get message “Undefined function ‘spm_select’ for input arguments of type ‘double’.”
    May you help me with this message ? should I install more things ?

    thanks in advance

Leave a Reply

Your email address will not be published. Required fields are marked *