Calling a class method from a GUI
显示 更早的评论
Hello there?
I am making a OOP test program that we can run at a GUI. The code for the class is
classdef test_1 < handle
properties
name
connectStatus = 0
end
methods
% Constructor
function obj = test_1(test_name)
obj.name = test_name
end
function status = getStatus(obj)
status = obj.connectStatus
end
function obj = setStatus(obj, newStatus)
obj.connectStatus = newStatus
end
end
end
When I run this on workspace, I found that it works fine. I can check the values of the attributes of the object and I can run the method suich as getStatus, setStatus.
Now I made a GUI and tried to run the method whenever I push a button on the GUI. But Matlab gives me error messages like
'Undefined variable "obj" or class "obj.getStatus"'.
Here, obj is the object that I created and getStatus is the method.
I think the problem is simple but I do not know how to solve this.
So, I will be very thankful if someone give me a tip.
Thanks.
1 个评论
snow John
2019-9-2
Hello sir,
I have met the same problem ,can you give me some cases as reference.
Your help will be appreciated.
Bset!
-John
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!