Undefined function for input arguments of type 'matlab.ui.Figure'.

8 Ansichten (letzte 30 Tage)
Huiming Dong
Huiming Dong am 30 Mär. 2021
Bearbeitet: Sanjana am 28 Sep. 2024
Hi All,
Trying to run the following code by calling imspline (imspline is a defined class: classdef imspline < handle):
h = imspline(gca,'lineColor',[1 0.5 0],'pointColor',[0.2 0.8 0.4],'lineWidth',5);
It gives this error: Undefined function 'addImPoint' for input arguments of type 'matlab.ui.Figure'. Please give some suggestions. Would this error related to MATLAB versions? Thanks a lot in advance.
function obj = imspline(varargin)
% Set figure and axis
if nargin > 0 && isnumeric(varargin{1})%HD Original Code
obj.hAx = varargin{1};
obj.hFig = get(obj.hAx,'Parent');
else
obj.hFig = figure;
obj.hAx = axes;
end
set(obj.hAx,'XlimMode','Manual','YlimMode','Manual');
hold(obj.hAx);
% Crosshair over axis
hFig = obj.hFig;
idxCopy = find(strcmp(varargin,'copy'));
if ~isempty(idxCopy)
import_struct = varargin{idxCopy+1}.exportProperties;
obj.lineColor = import_struct.lineColor;
obj.pointColor = import_struct.pointColor;
obj.lineWidth = import_struct.lineWidth;
obj.saveState = import_struct.saveState;
obj.isOpen = 0;
obj.addGraphics;
return
end
iptPointerManager(hFig);
crosshair = @(hFig, currentPoint)...
set(hFig, 'Pointer', 'crosshair');
iptSetPointerBehavior(obj.hAx,crosshair);
% Add new point at buttonup
obj.id.addImPoint_id = iptaddcallback(obj.hFig,'WindowButtonUpFcn',{@addImPoint,obj}); %HD Original Code (Error)
obj.id.animateSpline_id = [];
% Parse input arguments
for c = 1:length(varargin)
if ischar(varargin{c})
varargin{c} = lower(varargin{c});
end
end
idxLineColor = find(strcmp(varargin,'linecolor'));
idxPointColor = find(strcmp(varargin,'pointcolor'));
idxLineWidth = find(strcmp(varargin,'linewidth'));
if ~isempty(idxLineColor)
obj.lineColor = varargin{idxLineColor+1};
end
if ~isempty(idxPointColor)
obj.pointColor = varargin{idxPointColor+1};
end
if ~isempty(idxLineWidth)
obj.lineWidth = varargin{idxLineWidth+1};
end
end
function obj = addImPoint(src,event,obj)
pos = get(obj.hAx,'CurrentPoint');
button = get(obj.hFig,'SelectionType');
if strcmp(button,'normal')
% add new impoint and set properties
x = pos(1,1);
y = pos(1,2);
if isempty(obj.hVert)
obj.hLine = line(x,y,'Parent',obj.hAx);
set(obj.hLine,'Color',obj.lineColor,'LineWidth',obj.lineWidth);
end
hNewImpoint = impoint(obj.hAx,x,y);
hNewImpoint.setColor(obj.pointColor);
obj.hVert{end+1} = hNewImpoint;
if isempty(obj.id.animateSpline_id)
obj.id.animateSpline_id = iptaddcallback(obj.hFig,'WindowButtonMotionFcn',{@animateSpline,obj});
end
elseif strcmp(button,'alt')
% Remove old axis and figure properties
obj.isOpen = 0;
iptremovecallback(obj.hFig, 'WindowButtonMotionFcn',obj.id.animateSpline_id);
animateSpline_id = [];
iptremovecallback(obj.hFig, 'WindowButtonUpFcn',obj.id.addImPoint_id);
addImPoint_id = [];
iptSetPointerBehavior(obj.hAx,[]);
% Draw new spline and make it dragable
obj.drawSpline;
for cVert = 1:length(obj.hVert)
obj.hVert{cVert}.addNewPositionCallback(@refreshVertexPosition);
end
iptaddcallback(obj.hLine,'ButtonDownFcn',{@lineButtonDown,obj});
% Set the arrow pointer for the line
hFig = obj.hFig;
iptPointerManager(hFig);
pointerBehavior.enterFcn = @(hFig,currentPoint) set(hFig,'Pointer','Crosshair');
pointerBehavior.exitFcn = @(hFig,currentPoint) set(hFig,'Pointer','Arrow');
pointerBehavior.traverseFcn = [];
iptSetPointerBehavior(obj.hLine,pointerBehavior);
obj.isOpen = 0;
notify(obj,'SplineClosing');
notify(obj,'SplineUpdated');
end
function animateSpline(varargin)
obj.drawSpline;
end
function refreshVertexPosition(varargin)
obj.drawSpline;
notify(obj,'SplineUpdated');
end
end

Antworten (1)

Sanjana
Sanjana am 28 Sep. 2024
Bearbeitet: Sanjana am 28 Sep. 2024
Hi,
The above issue might be due to the following possible reasons,
  • Function Scope: Ensure that addImPoint function is defined within the same class defintion as imspline. MATLAB requires that all methods of a class be defined within the same file or be properly connected as methods of the class.
  • Method Declaration: If addImPoint is a method of the imspline class, it should be declared within the methods block of the class. Make sure it is properly declared as a method.
Hope this helps!

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by