command line vs GUI, toolbox failed
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am running a script on R2024a via command line and i have got this error:
cmd: matlab -nodisplay -nosplash -nodesktop -r "run('my_script.m'); exit;"
error: niftiinfo requires Image Processing Toolbox.
Of course i have Image Processing Toolbox already in the toolbox folder. In fact, when i run same script from the GUI, everything is going well. The path is correctly set otherwise even the GUI has to fail.
Someone has an idea?
Thanks
4 comentarios
Piyush Kumar
el 17 de Jun. de 2024
@Matteo, can you share the script so that I can try reproducing the error?
Respuestas (1)
Sanchari
el 8 de Jul. de 2024
Hello Matteo,
The issue encountered is likely due to the MATLAB command line session not having access to the Image Processing Toolbox, even though it is available when MATLAB is run through the GUI. This can happen if the toolbox is not properly added to the MATLAB path in the command line session or if there are licensing issues.
Here are some steps to troubleshoot and resolve this:
1. Verify the Toolbox Path
Ensure that the Image Processing Toolbox is correctly added to the MATLAB path in the command line session. Please consider modifying the script or add command to the command line to explicitly add the toolbox path.
For script, add the following lines to the beginning of "my_script.m":
addpath(fullfile(matlabroot, 'toolbox', 'images', 'images'));
addpath(fullfile(matlabroot, 'toolbox', 'images', 'imuitools'));
addpath(fullfile(matlabroot, 'toolbox', 'images', 'iptformats'));
addpath(fullfile(matlabroot, 'toolbox', 'images', 'iptutils'));
For command line, add the following command:
matlab -nodisplay -nosplash -nodesktop -r "addpath(genpath(fullfile(matlabroot, 'toolbox', 'images')));
run('my_script.m'); exit;
2. Check License Availability
Ensure that the Image Processing Toolbox license is available when running MATLAB from the command line. Please check this by running the following commands in the command line session:
matlab -nodisplay -nosplash -nodesktop -r "license('test', 'Image_Toolbox'); exit;"
If the output indicates that the license is not available, please proceed to resolve licensing issues.
3. Use "matlab.addons.installedAddons"
Please verify if the toolbox is installed and available by running the following command in the script:
installedToolboxes = matlab.addons.installedAddons;
disp(installedToolboxes);
This will display a list of installed toolboxes. Ensure that the Image Processing Toolbox is listed.
4. Verify MATLAB Version Consistency
Ensure that the MATLAB version being used in the command line is the same as the one used in the GUI. Sometimes, different versions might have different toolbox paths or licensing configurations.
For verifying with command line directly, type the following command:
matlab -nodisplay -nosplash -nodesktop -r "disp(['MATLAB Version: ' version]); exit;"
For verifying with GUI, type the following command:
disp(['MATLAB Version: ' version]);
If there are multiple MATLAB versions installed, ensure that the correct version is being used in the command line by specifying the full path to the MATLAB executable:
"/path/to/your/matlab/bin/matlab" -nodisplay -nosplash -nodesktop -r "run('my_script.m'); exit;"
Replace "/path/to/your/matlab/bin/matlab" with the path obtained from the "matlabroot" command in the GUI.
5. Use "niftiinfo" Function
If the toolbox is correctly added and the license is available, consider using the "niftiinfo" function as follows:
info = niftiinfo('the_nifti_file.nii');
disp(info);
Do remember to replace "the_nifti_file.nii" with the file being considered.
Please refer the following links for further knowledge on:
- addpath function (MathWorks Documentation): https://www.mathworks.com/help/matlab/ref/addpath.html?searchHighlight=addpath&s_tid=srchtitle_support_results_1_addpath
- license function (MathWorks Documentation): https://www.mathworks.com/help/matlab/ref/license.html?searchHighlight=license&s_tid=srchtitle_support_results_1_license
- matlabroot function (MathWorks Documentation): https://www.mathworks.com/help/matlab/ref/matlabroot.html?searchHighlight=matlabroot&s_tid=srchtitle_support_results_1_matlabroot
- niftiinfo function (MathWorks Documentation): https://www.mathworks.com/help/images/ref/niftiinfo.html?searchHighlight=niftiinfo%20function&s_tid=srchtitle_support_results_1_niftiinfo%20function
- user-defined function works with MATLAB command prompt but not with Linux treminal (ML Answers): A user-defined function while working with the matlab command prompt does not work from linux prompt! - MATLAB Answers - MATLAB Central (mathworks.com)
Hope this helps!
0 comentarios
Ver también
Categorías
Más información sobre Get Started with MATLAB Compiler en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!