MATLAB Answers

Method is not defined or is removed from MATLAB search path

103 views (last 30 days)
abblah abblah
abblah abblah on 17 Jun 2019
Commented: Steven Lord on 21 Jan 2020
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.


Show 6 older comments
Guillaume on 21 Jan 2020
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
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']);
fid = fopen(fullfile(classfolder, 'coolMethod1.m'), 'wt');
fprintf(fid, ['function coolMethod1(this)', newline, '\tfprintf(''Called class method, p: %%d\\n'', this.p);', newline, 'end']);
%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']);
disp('theirTool higher up in path than ourTool')
addpath(classparent); addpath(funfolder);
t = doCoolStuff;
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;
The class method is found regardless of which folder takes precedence in the path.
Paul Rancuret
Paul Rancuret on 21 Jan 2020
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!
Paul Rancuret
Steven Lord
Steven Lord on 21 Jan 2020
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)