Using matlab "system" to use fsl function: zsh:1: command not found

Hi, I am currently using nets_glm.m to analyze timeseries data. When I run:
system('randomise -i /private/var/folders/_t/nh0js0wn4pn2qvrpzc3_p6th0000gn/T/tpdd6495da_b958_4230_a49e_a51b1baf05c9 -o /private/var/folders/_t/nh0js0wn4pn2qvrpzc3_p6th0000gn/T/tpdd6495da_b958_4230_a49e_a51b1baf05c9 -d design/design.mat -t design/design.con -x -n 5000')
it will return: zsh:1: command not found: randomise.
However, when I run "randomise" function directly in zsh, it works well.
Could you please help me figure out the probelm?
Thanks

Answers (1)

I've used this solution, it works for me:
Basically add the path where the command is (usually in /usr/local/bin or where you install it).

5 Comments

this does not seem to work for me.
Any other WAR?
Setting the environment variables correctly has to do with what executables can be found when you use system() or the ! command in MATLAB. It does not provide a way for MATLAB to find .m or .mdl or .slx or similar -- use pathtool for that. It also does not provide a way to be able to execute external programs such as randomize or imglob from the MATLAB command line -- you have to system() or ! to run those.
@Walter Roberson I am still unable to run a command
"imglob"
commnad with system() in the following script
function par = dicom2nii(src, outfile)
%% Converting DICOM to NIFTI for 4D data
%
% Syntax:
% [filename, par] = dicom2nii(src, [options])
%
% Description:
% This function is an extension of the DICOM-to_NIFTI converter
% 'dicm2nii'. It converts a set of DICOM files to NIFTI format
% for 4D data. It supports the automatic conversion to a 4D NIFTI
% file.
%
% Input Arguments:
% src - the directory where DICOM files are located.
% outfile - the output NIFTI file.
%
% Output Arguments:
% par - a structure of DICOM parameters.
%
% Examples:
% dicom2nii('dcm','out.nii.gz');
%
% See also
%
% References:
%
% Notes:
% 1. This function requires the DICOM-to_NIFTI converter dicm2nii.
% https://www.mathworks.com/matlabcentral/fileexchange/42997-dicom-to-nifti-converter--nifti-tool-and-viewer
% 2. This function requires FSL, and works on Linux.
%
% History:
% 07/14/2016 - initial script.
%
%__________________________________________________________________________
% Wonsang You(wsgyou@gmail.com)
% 07/14/2016
% Copyright (c) 2016 Wonsang You.
%% converting DCM to NIFTI for each volume
path_str = fileparts('out.nii.gz');
niidir = fullfile(path_str,'nii');
subject = dicm2nii('/Users/cdinea/Downloads', niidir, '3D.nii.gz');
data = load(fullfile(niidir,'dcmHeaders.mat'));
prefix = fieldnames(data.h);
system(imglob)
%% concatenating 3D volumes into a 4D NIFTI files
system(sprintf('full_list=`imglob %s_?????.*`;fslmerge -t %s $full_list',fullfile(niidir,prefix{1}),'out.nii.gz'),'-echo');
system(sprintf('rm -f %s',niidir));
I get the following erros when running the script
>> dicom2nii
Xiangrui Li's dicm2nii.m 20230223 (feedback to xiangrui.li@gmail.com)
Validating 30800 files ... (1615 valid)
Converting 1 series (GE) into 3-D .nii.gz: subject '***'
x5_95_5_1_25MM 512x512x85x19
Please install pigz for fast compression: http://macappstore.org/pigz/
Elapsed time by dicm2nii is 212.6 seconds
Unrecognized function or variable 'imglob'.
Error in dicom2nii (line 47)
system(imglob)
@Walter Roberson thank you for the reply.Sorry for the double post.
I am using this converter to convert from 4D DICOM to 4D nifti data. The are some issues though and I get these errors
Image Exception : #63 :: No image files match: /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00001 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00002 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00003 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00004 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00005 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00006 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00007 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00008 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00009 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00010 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00011 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00012 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00013 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00014 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00015 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00016 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00017 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00018 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00019
libc++abi: terminating with uncaught exception of type std::runtime_error: No image files match: /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00001 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00002 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00003 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00004 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00005 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00006 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00007 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00008 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00009 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00010 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00011 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00012 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00013 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00014 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00015 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00016 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00017 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00018 /Users/cdinea/Downloads/nii/x5_95_5_1_25MM_00019
/Users/cdinea/fsl/bin/fslmerge -t /Users/cdinea/Downloads/out.nii.gz $full_list: Aborted
rm: /Users/cdinea/Downloads/nii/: is a directory

Sign in to comment.

Categories

Tags

Asked:

on 11 Dec 2021

Commented:

on 10 Mar 2023

Community Treasure Hunt

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

Start Hunting!