How to modify the handles structure (GUI) from an external function
20 views (last 30 days)
Show older comments
Hi,
I am developing a GUI. I can modify the handles structure (for example handles.variable1 = 2) within callbacks. However I am not able to do the same within an external function. E.g., this does not work:
function [matrix, indexVector] = myFunction(handles)
handles.variable1 = 1;
It is important to note that myFunction does not belong to the GUI callbacks, it is simply a function I have created in another m file. When I call it I can read the handles struture (actually im passing them as a parameter) but when I try to modify them the modification is not recorded.
Best,
-MRR
0 Comments
Accepted Answer
Sean de Wolski
on 8 Mar 2013
Edited: Sean de Wolski
on 8 Mar 2013
function [matrix, indexVector] = myFunction(handles)
handles.variable1 = 1;
guidata(handles.figure1,handles)
Where figure1 is the 'Tag' of the figure. You want to make sure that you assign the handles structure to the right place (i.e. the figure). hObject is dynamic, handles will always have the field for the figure.
More Answers (3)
Azzi Abdelmalek
on 8 Mar 2013
Use
function [matrix, indexVector] = myFunction(hObject,handles)
handles.variable1 = 1;
guidata(hObject,handles)
4 Comments
zakaria
on 5 Jun 2014
handles = guihandles(gcbo); % if not presents in the other external function
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements 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!