Freesurfer command in matlab
이전 댓글 표시
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,
답변 (3개)
Walter Roberson
2016년 6월 17일
1 개 추천
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
HARI GURAGAIN
2016년 6월 17일
편집: Walter Roberson
2016년 6월 17일
Kelly Kearney
2016년 6월 17일
Last I checked, Matlab makes some alterations to a few DYLD-related environment variables when it starts up. I found that those changes can cause problems when running system commands that rely on the dyld library. I put the following commands in my startup file:
setenv('DYLD_LIBRARY_PATH', '');
setenv('DYLD_FRAMEWORK_PATH', '');
and that seems to suffice to undo the errors.
Walter Roberson
2016년 6월 17일
It sounds as if your shell initialization also adds to DYLD_LIBRARY_PATH to bring in a different version of a library.
Really freesurfer should probably be re-linked; see http://stackoverflow.com/questions/13414786/missing-emutls-get-address-with-gcc-4-7-and-openmp
HARI GURAGAIN
2016년 6월 18일
편집: HARI GURAGAIN
2016년 6월 18일
Malcolm Lidierth
2016년 6월 18일
Note "shell initialisation" in WR's answer. Running setenv from MATLAB won't affect the path during initialization.
Walter Roberson
2016년 6월 18일
Each "!setenv" or system('setenv') would run in its own shell, but calling MATLAB's setenv() could work.
Malcolm Lidierth
2016년 6월 19일
@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).
neuromechanist
2023년 5월 26일
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.
Luis Lacerda
2017년 2월 16일
0 개 추천
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
Walter Roberson
2017년 2월 16일
Luis, to check: is the directory /Applications/freesurfer or is it /Applications/freesurfer.app ?
카테고리
도움말 센터 및 File Exchange에서 Historical Contests에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!