Undefined function for input arguments of type ‘matlab.ui.Figure’.
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
endHi 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 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 gui callback MATLAB Answers — New Questions