Undefined function 'SelectedPoint' for input arguments of type 'matlab.gr​aphics.cha​rt.primiti​ve.Line'. Error while evaluating Line ButtonDownFcn.

6 次查看(过去 30 天)
We are trying to use the ButtonDownFcn in a Matlab App code.
The @SelectedPoint function is defined in the methods section of the code, but the function doesn't work.
If the @SelectedPoint function is defined in the same section to where it was called - it works properly. (Meaning, if it is under the ButtonPushed section it works properly).
properties (Access = private)
Property % Description
pt;
comments;
comments_pt;
end
methods (Access = public)
function [point]=SelectedPoint(app, event)
figHandle=ancestor(app,'figure');
clicktype=get(figHandle,'SelectionType');
if strcmp(clicktype,'alt')
app.pt = [app.pt ; event.IntersectionPoint];
fprintf('[x,y,z] = [%.5f, %.5f]\n', app.pt)
hold on;
msg= ['Do You Want To Save The Selected Point?'];
title=[''];
selection = questdlg(msg,title, 'Yes','No','Yes');
if strcmp(selection,'Yes')
prompt = {'Enter Comments'};
dlgtitle='';
dims = [1 40];
definput = {'Enter Comments'};
app.comments = [app.comments ; inputdlg(prompt,dlgtitle,dims,definput)];
if isempty(app.comments)
selection='No';
else
pt=array2table(app.pt(:,1:2));
pt.Properties.VariableNames= {'X' 'Y'};
comments=cell2table(app.comments);
comments.Properties.VariableNames= {'Comments'};
app.comments_pt= [pt comments];
app.UITable.Data=app.comments_pt;
end
end
if strcmp(selection,'No') || isempty(selection)
app.pt(end, :)= [];
delete(p2);
end
end
end
% Button pushed function: Button
function ButtonPushed(app, event)
clf()
axh = axes();
x = rand(1,20);
y = rand(1,20);
z = rand(1,20);
h=plot3(axh,x,y,z)
xlabel('x axis')
ylabel('y axis')
grid on
h.ButtonDownFcn = @SelectedPoint;

回答(1 个)

Ishaan Mehta
Ishaan Mehta 2024-3-5
编辑:Ishaan Mehta 2024-3-5
Hi Tomer,
As I understnd, you wish to call a method defined in the application code, within the "methods" block, in a "ButtonPushedFcn" event handler, but are facing an error stating that the method is undefined.
This could be becuase in MATLAB App Designer, when you want to call a function defined in the "methods" section from an event callback such as a button's "ButtonPushedFcn", you should use the syntax "app.methodName(arguments)" to call the method. This is because the method belongs to the "app" object, and you need to specify that you are calling a method of this specific instance ("app") of your application class.
If you wish to assign the "SelectedPoint" method as the "ButtonPushFcn" callback, you can add the callback function, and then call "app.SelectedPoint" within the callback function. This will effectively call the "SelectedPoint" method when the button is pushed.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by