MATLAB Answers

0

Freesurfer command in matlab

Asked by HARI GURAGAIN on 17 Jun 2016
Latest activity Answered by software on 20 Mar 2018
I am trying to execute freesurfer commands from MATLAB. I used the command like: command ='mri_info --vox2ras-tkr subjects/ABC/mri/orig.mgz'. The matlab is showing the following message: "/bin/bash:mri_info: command not found" with status = 127. If I use termainal to execute the same command, it will work. I just wonder if it is related to linking the path? Some other simple commands like: 'whoami' or 'who' are working. Any help will be appreciated.
Thanks,

  0 Comments

Sign in to comment.

3 Answers

Answer by Walter Roberson
on 17 Jun 2016

It sounds like you have a .bashrc or .env file that is responsible for adding some things to your PATH environment variable. Depending on the details of how you are starting up MATLAB, your shell initialization might not be run, so those things might not be on your PATH.
The easiest thing to do is to provide the complete path for the mri_info command when you invoke it.

  7 Comments

Note "shell initialisation" in WR's answer. Running setenv from MATLAB won't affect the path during initialization.
Each "!setenv" or system('setenv') would run in its own shell, but calling MATLAB's setenv() could work.
@Walter
My MATLAB's a bit rusty as I've been working in other languages for a few years. Maybe the setenv should be called from matlabrc.m. That would maximise the chance of it having been called when required. If that works, try moving it to startup.m - which is a bit more distribution friendly. And if that works, maybe try including it in a file invoked using the -r switch at the command line so it gets called straight after startup.
There is a general problem that TMW often distributes legacy open-source resources as part of the MATLAB distribution e.g. with jar files (which I'm more familiar with). It's understandable that they should be reluctant to update these on every release as any upgrade runs a risk of breaking their own code. Nevertheless, it does lead to situations where the distro is partially broken at outset: e.g. some time ago, individual jars that together make up the Apache Batik distro for SVG support were from different releases and did not work together fully. Particularly when there are many component files, sorting out which release each comes from can be problematic.
Settling on using the same release distributed with MATLAB often makes sense; until end-users start complaining that their m-code using the latest features doesn't work (prime example until a few years ago: JOGL).

Sign in to comment.


Answer by Luis Lacerda on 16 Feb 2017

Dear Hari,
I have recently been able to fix this problem by adding the freesurfer path to the shell path from the system.
As someone said previously, you can use the matlab setenv function to do so; the first step is just to get the current PATH (please see below)
bash_path=getenv ('PATH');
setenv( 'PATH',[bash_path,':/Applications/freesurfer',':/Applications/freesurfer/bin']);
I have added these two lines to my startup.m file and can now run freesurfer commands by calling them with the function system or simply !free_surfer command
Cheers
Luis

  1 Comment

Luis, to check: is the directory /Applications/freesurfer or is it /Applications/freesurfer.app ?

Sign in to comment.


Answer by software on 20 Mar 2018

Hi is there anything in matlab that can extract similar clinical features from .nii MRI files as that of freesurfer ...ofcourse in less time !!

  0 Comments

Sign in to comment.