Unable to run local function "myparse"

조회 수: 6 (최근 30일)
Wai Cheng
Wai Cheng 2024년 10월 28일
댓글: Wai Cheng 2024년 10월 30일
I am unable to run a local function "myparse" even though it is already on my path. Anyone has any idea how to solve this?
>> ver
-----------------------------------------------------------------------------------------
MATLAB Version: 23.2.0.2668659 (R2023b) Update 9
MATLAB License Number: STUDENT
Operating System: macOS Version: 14.4.1 Build: 23E224
Java Version: Java 1.8.0_392-b08 with Amazon.com Inc. OpenJDK 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------
MATLAB Version 23.2 (R2023b)
Image Processing Toolbox Version 23.2 (R2023b)
M2HTML Toolbox - A Documentation Generator for ... Version 1.4
Parallel Computing Toolbox Version 23.2 (R2023b)
Statistics and Machine Learning Toolbox Version 23.2 (R2023b)
Thank you!
  댓글 수: 6
Wai Cheng
Wai Cheng 2024년 10월 28일
편집: Walter Roberson 2024년 10월 29일
function varargout = myparse(params,varargin)
nin = length(varargin)/2;
nout = nargout;
if mod(2*nin,2)~=0 || mod(length(params),2)~=0,
error('Odd number of parameters expected');
end;
% set defaults
varargout = varargin(2:2:2*nout);
% parameter names
names = varargin(1:2:end);
% go through parameters
for i = 1:2:length(params),
% check if it matches names{j}
if ~ischar(params{i}),
error('Input %d is not a string.',i);
end
%BJA: 6x faster than that below
idx=find(strcmpi(params{i},names));
if(isempty(idx))
warning('myparse:unknownParameterName','Unknown parameter name: %s, ignoring\n',params{i});
else
varargout{idx} = params{i+1};
end
% if ~any(strcmpi(params{i},names)),
% warning('myparse:unknownParameterName','Unknown parameter name: %s, ignoring\n',params{i});
% end
%
% for j = 1:length(names),
%
% % set value
% if strcmpi(params{i},names{j}),
% varargout{j} = params{i+1};
% end;
%
% end;
end;
Thank you.
Rahul
Rahul 2024년 10월 28일
편집: Rahul 2024년 10월 28일
@Wai Cheng, I am unable to reproduce the issue you have provided in MATLAB R2023b. The issue could be encountered if possibly some another function with name 'myparse' could be on MATLAB path, for which you can use the following command:
>> which myparse
If you find another function, you can try removing the undesired function from path manually, and in case you don't find the desired myparse file on path, you can add it using the following command:
>> addpath('path/to/your/desired/myparse.m')
You can try restarting your current MATLAB session.
The best practice here could be to rename the given function, since often MATLAB can check in folders with the same name as the function, which might not be installed.
To find the products, toolboxes and files required by a specific code or file, you can use the following function:
[~, products] = matlab.codetools.requiredFilesAndProducts('myparse.m');
disp(products.Name)
In your case, the products array contains a single element with name 'MATLAB' stating no requirement for 'Medical Imaging Toolbox'.

댓글을 달려면 로그인하십시오.

답변 (4개)

Tushar Sharma
Tushar Sharma 2024년 10월 28일
Hi Wai,
It seems that the function you're trying to use, "myparse," may be causing conflicts in MATLAB. The error you're experiencing typically occurs when a function in your folder has the same name as a toolbox function for which you don't have a license. As a workaround, I suggest renaming your function.
To help identify name conflicts, although only for installed toolboxes, you might find this function useful: https://www.mathworks.com/matlabcentral/fileexchange/27861-uniquefuncnames
  댓글 수: 1
Wai Cheng
Wai Cheng 2024년 10월 30일
Hi Tushar, I've tried renaming the function but when I call the new function the same error comes out. UniqueFuncNames did not list "myparse" as conflicting as well.
>> UniqueFuncNames
Conflicting files:
-- fernsClfApply:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/misc/fernsClfApply.m
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/toolbox/classify/fernsClfApply.m
-- fernsClfTrain:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/misc/fernsClfTrain.m
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/toolbox/classify/fernsClfTrain.m
-- filterGauss:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/pdollarOF/filterGauss.m
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/toolbox/filters/filterGauss.m
-- convnFast:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/pdollarOF/convnFast.m
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/toolbox/images/convnFast.m
-- gaussSmooth:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/pdollarOF/gaussSmooth.m
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/toolbox/images/gaussSmooth.m
-- im:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/pdollarOF/im.m
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/toolbox/images/im.m
-- localSum:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/pdollarOF/localSum.m
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/toolbox/images/localSum.m
-- checkNumArgs:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/pdollarOF/checkNumArgs.m
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/toolbox/matlab/checkNumArgs.m
-- uigetdir2:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/misc/uigetdir2.m
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/filehandling/uigetdir2.m
-- SaveFigLotsOfWays:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/misc/SaveFigLotsOfWays.m
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/perframe/SaveFigLotsOfWays.m
-- SelectHistEdges:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/misc/SelectHistEdges.m
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/perframe/SelectHistEdges.m
-- findjobj:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/misc/findjobj.m
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/perframe/findjobj.m
-- myfileparts:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/misc/myfileparts.m
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/perframe/myfileparts.m
-- vectorize:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/misc/vectorize.m
/Applications/MATLAB_R2023b.app/toolbox/matlab/funfun/vectorize.m
/Applications/MATLAB_R2023b.app/toolbox/matlab/funfun/@inline/vectorize.m
-- savefig:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/toolbox/external/other/savefig.m
/Applications/MATLAB_R2023b.app/toolbox/matlab/graphics/objectsystem/savefig.m
-- csvwrite:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/misc/csvwrite.m
/Applications/MATLAB_R2023b.app/toolbox/matlab/iofun/csvwrite.m
-- imtranslate:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/toolbox/external/deprecated/imtranslate.m
/Applications/MATLAB_R2023b.app/toolbox/images/images/imtranslate.m
-- imwarp:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/optflow_deqing/utils/imwarp.m
/Applications/MATLAB_R2023b.app/toolbox/images/images/imwarp.m
/Applications/MATLAB_R2023b.app/toolbox/images/images/@gpuArray/imwarp.m
-- psnr:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/optflow_deqing/utils/psnr.m
/Applications/MATLAB_R2023b.app/toolbox/images/images/psnr.m
/Applications/MATLAB_R2023b.app/toolbox/images/deep/@dlarray/psnr.m
-- drawellipse:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/misc/drawellipse.m
/Applications/MATLAB_R2023b.app/toolbox/images/imuitools/drawellipse.m
-- montage:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/misc/montage.m
/Applications/MATLAB_R2023b.app/toolbox/images/imuitools/montage.m
-- pdist2:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/spaceTime/toolbox/classify/pdist2.m
/Applications/MATLAB_R2023b.app/toolbox/stats/stats/pdist2.m
/Applications/MATLAB_R2023b.app/toolbox/stats/bigdata/@tall/pdist2.m
/Applications/MATLAB_R2023b.app/toolbox/stats/gpu/@gpuArray/pdist2.m
-- pco_uint32:
/Users/chrisgwwc/Library/Application Support/MathWorks/MATLAB Add-Ons/Toolboxes/PIVlab/PIVlab_capture_resources/PCO_resources/scripts/ver_8/pco_uint32.m
/Users/chrisgwwc/Library/Application Support/MathWorks/MATLAB Add-Ons/Toolboxes/PIVlab/PIVlab_capture_resources/PCO_resources/scripts/ver_7/pco_uint32.m
/Users/chrisgwwc/Library/Application Support/MathWorks/MATLAB Add-Ons/Toolboxes/PIVlab/PIVlab_capture_resources/PCO_resources/scripts/pco_uint32.m
-- pco_uint32err:
/Users/chrisgwwc/Library/Application Support/MathWorks/MATLAB Add-Ons/Toolboxes/PIVlab/PIVlab_capture_resources/PCO_resources/scripts/ver_8/pco_uint32err.m
/Users/chrisgwwc/Library/Application Support/MathWorks/MATLAB Add-Ons/Toolboxes/PIVlab/PIVlab_capture_resources/PCO_resources/scripts/ver_7/pco_uint32err.m
/Users/chrisgwwc/Library/Application Support/MathWorks/MATLAB Add-Ons/Toolboxes/PIVlab/PIVlab_capture_resources/PCO_resources/scripts/pco_uint32err.m
-- pco_uint32:
/Users/chrisgwwc/Library/Application Support/MathWorks/MATLAB Add-Ons/Toolboxes/PIVlab/PIVlab_capture_resources/PCO_resources/scripts/ver_8/pco_uint32.m
/Users/chrisgwwc/Library/Application Support/MathWorks/MATLAB Add-Ons/Toolboxes/PIVlab/PIVlab_capture_resources/PCO_resources/scripts/ver_7/pco_uint32.m
/Users/chrisgwwc/Library/Application Support/MathWorks/MATLAB Add-Ons/Toolboxes/PIVlab/PIVlab_capture_resources/PCO_resources/scripts/pco_uint32.m
-- pco_uint32err:
/Users/chrisgwwc/Library/Application Support/MathWorks/MATLAB Add-Ons/Toolboxes/PIVlab/PIVlab_capture_resources/PCO_resources/scripts/ver_8/pco_uint32err.m
/Users/chrisgwwc/Library/Application Support/MathWorks/MATLAB Add-Ons/Toolboxes/PIVlab/PIVlab_capture_resources/PCO_resources/scripts/ver_7/pco_uint32err.m
/Users/chrisgwwc/Library/Application Support/MathWorks/MATLAB Add-Ons/Toolboxes/PIVlab/PIVlab_capture_resources/PCO_resources/scripts/pco_uint32err.m
-- exportfig:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/misc/exportfig.m
/Users/chrisgwwc/Library/Application Support/MathWorks/MATLAB Add-Ons/Toolboxes/PIVlab/exportfig.m
-- uipickfiles:
/Users/chrisgwwc/Documents/MATLAB/JAABA-master/misc/uipickfiles.m
/Users/chrisgwwc/Library/Application Support/MathWorks/MATLAB Add-Ons/Toolboxes/PIVlab/uipickfiles.m
failed: 5008 functions checked, some are not unique.
>> mycustomparse
Unrecognized function or variable 'mycustomparse'.
>> mycustomparse
mycustomparse requires Medical Imaging Toolbox.

댓글을 달려면 로그인하십시오.


埃博拉酱
埃博拉酱 2024년 10월 28일
As @Tushar Sharma said, there's a naming conflict. However as @Rahul said, I also can't reproduce this issue. In my experience, MATLAB is generally able to handle the vast majority of naming conflicts correctly. If you don't want to change your function name, you can also try removing your folder from the search path and then adding it again.
It's a good practice for third-party toolboxes to use namespaces to avoid conflicts with official functions.

Rahul
Rahul 2024년 10월 28일
편집: Rahul 2024년 10월 29일
Hi Wai Cheng,
I understand that you are trying to execute a local function in MATLAB R2023b but getting an error stating “mpyarse requires Medical Imaging Toolbox”.
I am unable to reproduce the issue you have reported, in MATLAB R2023b. The issue could be encountered if possibly some another function with name 'myparse' could be on MATLAB path, for which you can use the following command:
>> which myparse
If you find another function, you can try removing the undesired function from path manually, and in case you don't find the desired myparse file on path, you can add it using the following command:
>> addpath('path/to/your/desired/myparse.m')
You can try restarting your current MATLAB session.
Although, the best practice here could be to rename the given function, since often MATLAB can check for conflicts in folders with the same name as the function, which might not be installed.
Moreover, to find the products, toolboxes and files required by a specific code or file, you can use the following function:
[~, products] = matlab.codetools.requiredFilesAndProducts('myparse.m');
disp(products.Name)
In your case, the products array contains a single element with name 'MATLAB' stating no requirement for 'Medical Imaging Toolbox'.
Hope this helps!

Walter Roberson
Walter Roberson 2024년 10월 29일
You could potentially have that problem if your setup function is adding the directory to the end of the MATLAB path instead of at the beginning of the MATLAB path.
  댓글 수: 1
Wai Cheng
Wai Cheng 2024년 10월 30일
Thank you Walter. Please correct me if I'm wrong, but I've rmpath and addpath to the beginning. "which myparse" command is showing the correct path, but it's still not working.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by