Freesurfer command in matlab

82 vues (au cours des 30 derniers jours)
HARI GURAGAIN
HARI GURAGAIN le 17 Juin 2016
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,

Réponses (3)

Walter Roberson
Walter Roberson le 17 Juin 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 commentaires
Walter Roberson
Walter Roberson le 18 Juin 2016
Each "!setenv" or system('setenv') would run in its own shell, but calling MATLAB's setenv() could work.
Malcolm Lidierth
Malcolm Lidierth le 19 Juin 2016
@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).

Connectez-vous pour commenter.


Luis Lacerda
Luis Lacerda le 16 Fév 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 commentaire
Walter Roberson
Walter Roberson le 16 Fév 2017
Luis, to check: is the directory /Applications/freesurfer or is it /Applications/freesurfer.app ?

Connectez-vous pour commenter.


neuromechanist
neuromechanist le 26 Mai 2023
It iturns out the Matlab's shell may not respect the system shell env variables. So, to make FreeSurfer work, you can have the following lines in the startup.m file (find your startup.m using this command: edit(fullfile(userpath,'startup.m')))
bash_path=getenv('PATH');
setenv('PATH',[bash_path,':/Applications/freesurfer/7.4.0',':/Applications/freesurfer/7.4.0/bin']);
setenv('FREESURFER_HOME', '/Applications/freesurfer/7.4.0')
setenv('SUBJECTS_DIR', '$FREESURFER_HOME/subjects')
system('source $FREESURFER_HOME/SetUpFreeSurfer.sh')
This snippet assumes that the freesurfer software is installed under Applications. Thanks @Luis Lacerda for the hint.

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by