Running FSL commands from Matlab

Yes, you can run FSL from Matlab. Here is how – two step process for me (but it could be more efficient, if need be):

(a) First, launch Matlab (assuming on a Mac) from a terminal that is already setup for FSL (see here for more info)

/Applications/<matlab_folder>/bin/matlab &

(b) Second, at the beginning of your Matlab script, add the following lines of code. This way Matlab knows where does FSL exist,

    % set FSL environment
setenv(‘FSLDIR’,'/usr/local/fsl’);  % this to tell where FSL folder is
setenv(‘FSLOUTPUTTYPE’, ‘NIFTI_GZ’); % this to tell what the output type would be

That’s it and you can launch any FSL command as follows,

cmd = ‘/usr/local/fsl/bin/feat design.fsf’;
system(cmd);

Hope that helps!

About these ads
This entry was posted in fmri, fsl, matlab. Bookmark the permalink.

One Response to Running FSL commands from Matlab

  1. Matt Wall says:

    That’s a very neat little trick! Thanks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s