How to pass a variable to a function created using the manual

I developed a GUI in MATLAB GUIDE. What is the best way to make data from an external function or class available to functions created by GUIDE?

+2
source share
2 answers

The links provided by ymihere look very useful. In addition, some of the options (nested functions and using GUIDATA ) discussed in these links are covered in another SO post: How do I create a GUI inside a function in MATLAB? There are several examples of how the code looks for each case.

, , , . , , , MATLAB ( ). , UserData ( ymihere). GUID GUIDE "myGUI.m", :

>> hGUI = myGUI('UserData','hello');

hGUI - GUI. UserData, , "hello":

>> get(hGUI,'UserData')

ans =

hello

"" , , . 'UserData' m GUIDE. handles, .

EDIT: UserData , , , ( ) . GUI , -, . , .

+3

, , , , UserData:

somevar myfig:

h = myfig('UserData', somevar);

:

h = myfig();
[...]
set(h, 'UserData', somevar);

:

function some_Callback(hObject, eventdata, handles)
    somevar = get(hObject, 'UserData');

.

+2

Source: https://habr.com/ru/post/1706737/


All Articles