Why can't I use the object that the uicontrol creates within a class created GUI?
显示 更早的评论
I need to use the variable created in the callback function, but anytime I try, I get an error saying that I'm pretty much trying to convert an instance of my class to a number. Is it an issue with the get function or of the uicontrol within a class?
classdef LaserFilterTest < handle
properties
fig;
title_405;
menu_405;
end
properties(Access = private)
callback_405;
end
methods
function obj = LaserFilterTest()
obj.fig = figure;
obj.callback_405 = @setpos3;
obj.title_405 = uicontrol(obj.fig, 'Style', 'text', ...
'String','405 Laser','Position', [20 350 100 20]);
obj.menu_405 = uicontrol(obj.fig,'Style','popup', ...
'String', '100%|50%|25%|10%|5%|1%', ...
'Position', [20 300 100 50], ...
'Callback',{@(src,event)setpos3(obj,src,event)});
end
end
methods(Access = private)
function setpos3(obj,src,event)
val = get(obj,'Value');
disp(val,'this value is')
end
end
end
回答(1 个)
per isakson
2014-4-22
编辑:per isakson
2014-4-22
There are different types of objects (, which is a bit confusing)
- handle graphic objects
- instances of user classes
The line, which causes the error should read
val = get(obj.menu_405,'Value');
I trust that you fix the problem with disp
类别
在 帮助中心 和 File Exchange 中查找有关 Update figure-Based Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!