I'm writing an OO gui program and I'm having issues trying to use the set()
function to change GUI element properties. I'm simply trying to change a buttons enable property from off to on. I have attached abridged code showing the same problem below. The way matlab handles classes etc feels rather strange so the problem might simply be caused by my misunderstanding of the system. Anyway, when I attempt to use the set()
function on the handle AD.buttonExit
, it works as expected when I execute the command in the initUI()
function. If I try to do the same in a different function, it fails. I checked the stacks by simply printing the contens of AD
. In the initUI
function it clearly shows a handle value for buttonExit
, it doesn't in the constructor function (or any other class-member-function). I feel like I'm making a elementary mistake, however I don't see it and I hope someone might be able to assist me.
-- rfhigler
code (abridged for clarity):
classdef test
properties
AppUI;
buttonExit;
end
methods
function AD = test()
%draws UI
AD.initUI();
set(AD.buttonExit, 'Enable', 'on')
AD.test2()
end
function initUI(AD)
AD.AppUI = figure('Visible','off','Position',[520,321,695,482], 'MenuBar', 'none', 'Name', '3D Particle Tracking',...
'NumberTitle', 'off', 'Resize', 'off', 'Color', [0.94,0.94,0.94]);
AD.buttonExit = uicontrol('Enable', 'off', 'Style', 'pushbutton', 'Visible', 'on', 'Position', [35,29,181,31], 'String', 'Exit');
set(AD.AppUI, 'Visible', 'on');
%1 set(AD.buttonExit, 'Enable', 'on')
end
function test2(AD)
set(AD.buttonExit, 'Enable', 'on')
end
end
end