MATLAB Answers

0

Using variables in multiple Callbacks

Asked by Jared Johnson on 4 Dec 2015
Latest activity Answered by Parham Ebrahimi on 15 Jul 2019
I have two different pop up menu callbacks (popupmenu1 and popupmenu2). In both callbacks I produce a variable, urlA and urlB respectively. How can I use these variables in my pushbutton1 call back? Created GUI using GUIDE. I've read the documentation and help on handles, but I can't quite get anything working.
I tried using global variables, but it isn't working quite as it should.

  1 Comment

Adam
on 4 Dec 2015
Since you have read the documentation on handles it would help if you post what you currently have.
In particular this you should read up on these for sharing data between callbacks:

Sign in to comment.

1 Answer

Answer by Parham Ebrahimi on 15 Jul 2019

You can first store the variable in a structure inside one of the Callback functions. Look at the example below:
function first_callback(hObject,handles)
handles.myvariable=urlA
guidata(hObject,handles)
end
Then you can retrive the stored structure in the other callback function:
function second_callback(hObject,eventdata)
guidata(hObject)%This will give back the variable "urlA" from previous callback function
end

  0 Comments

Sign in to comment.