MATLAB Answers

Method is not defined or is removed from MATLAB search path

112 views (last 30 days)
abblah abblah
abblah abblah on 17 Jun 2019
Commented: Steven Lord on 21 Jan 2020 at 22:21
Hi, this error occurs in the new versions of MATLAB (version = 2018b)
This error occurs when you have defined a method in a separate file,
This occurs for the both static and regular methods.
When every thing is correct and even the MATLAB auto-completion finds the method,
but when you call the method, the error "Method is not defined or is removed from MATLAB search path" occurs.
Note that this error is automatically resolved when MATLAB is restarted multiple times!
I think it is a bug in the new versions.

  9 Comments

Show 6 older comments
Guillaume
Guillaume on 21 Jan 2020 at 12:51
Yes, neither bullet point should be true. and I can't reproduce the issue (R2019b but while there's been some changes to scoping, it shouldn't apply to this case):
%all paths relative to current folder
classparent = 'ourTools';
classfolder = fullfile(classparent, '@doCoolStuff');
funfolder = 'theirTools';
%create required folders
mkdir(classfolder); mkdir(funfolder);
%create class files
%ourTools\@doCoolStuff\doCoolStuff.m
%ourTools\@doCoolStuff\coolMethod1.m
fid = fopen(fullfile(classfolder, 'doCoolStuff.m'), 'wt');
fprintf(fid, ['classdef doCoolStuff', newline, '\tproperties', newline, '\t\tp;', newline, '\tend', newline, '\tmethods', newline, ...
'\t\tfunction this = doCoolStuff', newline, '\t\t\tthis.p = randi(1000);', newline, '\t\tend', newline, '\tend', newline, 'end']);
fclose(fid);
fid = fopen(fullfile(classfolder, 'coolMethod1.m'), 'wt');
fprintf(fid, ['function coolMethod1(this)', newline, '\tfprintf(''Called class method, p: %%d\\n'', this.p);', newline, 'end']);
fclose(fid);
%create function file theirTools\coolMethod1.m
fid = fopen(fullfile(funfolder, 'coolMethod1.m'), 'wt');
fprintf(fid, ['function coolMethod1(~)', newline, '\tfprintf(''Called function, p: %%d\\n'', -randi(1000));', newline, 'end']);
fclose(fid);
disp('theirTool higher up in path than ourTool')
addpath(classparent); addpath(funfolder);
t = doCoolStuff;
t.coolMethod1;
coolMethod1(t);
coolMethod1(pi);
clear('classes'); %#ok<CLCLS>
disp('ourTool higher up in path than theirTool')
classparent = 'ourTools';
funfolder = 'theirTools';
rmpath(classparent); rmpath(funfolder);
addpath(funfolder); addpath(classparent);
t = doCoolStuff;
t.coolMethod1;
coolMethod1(t);
coolMethod1(pi);
The class method is found regardless of which folder takes precedence in the path.
Paul Rancuret
Paul Rancuret on 21 Jan 2020 at 20:10
Guillaume and Steven Lord,
I apologize, I made a very stupid mistake. I thought the particular 'ourTools' folder I'm describing was on the path, but I had a typo in the script I used to set my path, so it wasn't actually on the path. Only the children of 'ourTools' were actually added to my path (other than the method folder described). So that was my problem all along.
Sorry for wasting your time, and I appreciate that you did look at this for me!
Regards,
Paul Rancuret
Steven Lord
Steven Lord on 21 Jan 2020 at 22:21
In that case, would it be fair to eliminate the "bug in matlab [sic] path" tag from this question since it didn't turn out to be a bug with the search path?

Sign in to comment.

Answers (0)

Sign in to answer this question.