Accessing variables inside Callbacks

6 views (last 30 days)
Gor
Gor on 9 Aug 2013
Hi,
I have a problem I was facing the last couple of hours.
I am confused because I took the same code from gui dialog window and the same code doesn't work in my gui.
I want to assign the output of gui the a variable when I click the submit button, and in case if I cancel I want an empty array (or NaN, whatever) to be assigned. So, in the callback of "next" button the assignment should take place, after which the variable should be updated in handles, and output function should assing it to the var whcih called the gui. But exactly the part with transfering the variables from the callback to handles doesn't work.
Here es how the relevant part of the code looks like:
function obj_add_motion_OpeningFcn(hObject, eventdata, handles, varargin)
handles.out=[]; % Initialising with an empty value (for cancel, close)
% Update handles structure
guidata(hObject, handles);
uiwait(handles.figure1);
function varargout = obj_add_motion_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.out;
% The figure can be deleted now
delete(handles.figure1);
function btn_next2_Callback(hObject, eventdata, handles)
handles.out.v0=str2num(get(handles.V0, 'String'));
handles.out.a=str2num(get(handles.a, 'String'));
handles.out.x_end=str2num(get(handles.x_end, 'String'));
handles.out.y_end=str2num(get(handles.y_end, 'String'));
guidata(hObject,handles) %also with (handles.out, handles) doesn't % work
guidata(hObject,handles);
uiresume(handles.figure1);
function figure1_CloseRequestFcn(hObject, eventdata, handles)
if isequal(get(hObject, 'waitstatus'), 'waiting')
% The GUI is still in UIWAIT, us UIRESUME
uiresume(hObject);
else
% The GUI is no longer waiting, just close it
delete(hObject);
end
I am pretty confused, seems to be that right the same things works in exampledialog box from matlab. It doesn't work out to get the structure from the callback to the global system.
Thanks, Gor
  2 Comments
Jan
Jan on 10 Aug 2013
What is "the global system"? Do you mean the base workspace, which is the workspace, which is active when you type in the command window?
Jan
Jan on 10 Aug 2013
[Relocated from answer section] Gor wrote:
Yes, I mean the base workspace. Thanks for a fast response Jan. I found out the bug in the meantime. The problem was, that the callback, where the code was, was never used. Something went wrong with the callback linked to the button in guide. It wasn't linked to any other callback, nor to the one it should. After searching really long I found that out.
Something for me to remember: while copying and pasting all the uicontrols it is good the check whether all the callbacks are linked as they should or not. This problem shouldn't occur normally, but still.

Sign in to comment.

Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!