So I have a class which inherits from the handle
superclass like this:
classdef testClass < handle
properties(Access = private)
handles_gui;
end
methods(Access = public)
function obj = testClass
% Preferably like to get inputname here
obj.handles_gui = obj.init_gui();
end
function callback_test(obj,hObject,eventdata)
disp(inputname(1));
end
end
methods(Access = private)
function handles_gui = init_gui(obj)
handles_gui.figure = figure( ...
'Tag', 'figure', ...
'Units', 'characters', ...
'Position', [50 35 167 25]);
handles_gui.button_left = uicontrol( ...
'Parent', handles_gui.figure, ...
'Units', 'characters', ...
'Position', [41 1.2 8 1.8], ...
'String', 'Test', ...
'Callback', @(hObject,eventdata) callback_test(obj,hObject,eventdata));
end
end
end
I'd like to preferably obtain the object's workspace name in the constructor. Not sure if this is possible since I'm not sure if the name is assigned until after creation of the object. If thats the case, then I'd like to obtain it through a callback. I have a gui, but in order to properly pass the obj
handle, I have to define the callback by passing obj
in the init_gui
function. This means that when inputname
is called for callback_test
when the button is pressed, it returns 'obj'
, since it's defined in the callback definition. But, if I call callback_test
through the terminal, it returns the proper variable name (the results make sense, but it's not what I want). An example is shown below:
EDU>> test = testClass;
obj (this was called by clicking on the button)
EDU>> test.callback_test
test
EDU>>
So my question is: how can I obtain the variable name, preferably in the constructor, and if not, then how can I obtain it through the callback without having to use the terminal.