External class method invocation error

조회 수: 4 (최근 30일)
John Dolan
John Dolan 2019년 4월 9일
댓글: John Dolan 2019년 4월 11일
Error message: Error using UGV/rotateby Method 'rotateby' is not defined for class 'UGV' or is removed from MATLAB's search path
I am getting this error when calling a method defined in a sibling function m-file within the class folder holding the class definition file. Here is the directory structure, which looks correct according the the help documentation.
Strange that this code was executing without error 1 day ago. I tried clearing and recreating the object instance. I rehashed the path. I examined the path and the parent folder of the class folder @UGV is on Matlab's search path as per definitions in help for external methods.
Here is the a snippet of the class definition in @UGV/UGV.m:
classdef UGV
properties
dunit = 'foot';
wheeltrack = 2.5; % default track 2.5 ft
wheelbase = 1.25; % default wheelbase 1.25 ft
rho; % rotation radius
...
end
methods
function obj = UGV()
tau = obj.wheeltrack / 2;
beta = obj.wheelbase / 2;
obj.rho = sqrt(tau^2 + beta^2); % rotation radius
end
...
% Rotation trajectory methods
traj = rotateby(obj, ang); % core radian version <<<<< This is the method that is failing
function traj = rotatebyd(obj, deg) % degree version <<<< an internal method that executes
traj = rotateby(obj, deg/180*pi); % but fails on call to external method
end
...
end
...
end
Here is the signature in the @UGV/rotateby.m file
function traj = rotateby(obj, ang)
% rotate UGV instance by angle ang
...
end
Again everything was working until just recently, so I am not sure what is broken. The path and directory structure looks correct. The method signature in the classdef matches that of the external method file. The problem is not an execution error, but the fact that Matlab can't seem to find the method file or doesn't associate it with the class. But help says that Matlab interprets all function m-files in the same class folder as methods of the sibling classdef.
  댓글 수: 3
John Dolan
John Dolan 2019년 4월 10일
Okay. This morning as a last resort, I quit my Matlab session and restarted.
And magically, the issue disappeared...??
I'm not sure what was corrupted, but Mathworks may want to log the issue in case other users encounter this.
Catalytic
Catalytic 2019년 4월 10일
but Mathworks may want to log the issue in case other users encounter this.
It's doubtful that they will. Matt J has already pointed out an error in your set-up. Any MathWorks staff who read this have no reason to think the issue goes any deeper than that.

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

채택된 답변

Matt J
Matt J 2019년 4월 9일
@UGV is on Matlab's search path
It should not be. The parent folder of @UGV should be on the search path, but not @UGV itself.
  댓글 수: 1
John Dolan
John Dolan 2019년 4월 11일
This must have been the problem. However, when I checked 'path' the class folder didn't appear... or perhaps I missed it. I must have done an add folder and subfolders in an ancestor directory.
Anyway, good to have a handle on what caused this, and I will be more careful going forward.
Thx.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by