GUI listbox example file of matlab: A structure 'handles' is being used throughout although it hasnt been defined in the program? I don't understand how is this happening?
조회 수: 6 (최근 30일)
이전 댓글 표시
The structure handles in the lbox2.m example is being rigorously used. The consider following code segment:
1 function load_listbox(dir_path,handles)
2 cd (dir_path)
3 dir_struct = dir(dir_path);
4 [sorted_names,sorted_index] = sortrows({dir_struct.name}');
5 handles.file_names = sorted_names;
6 handles.is_dir = [dir_struct.isdir];
7 handles.sorted_index = sorted_index;
8 guidata(handles.figure1,handles)
9 set(handles.listbox1,'String',handles.file_names,...
10 'Value',1)
11 set(handles.text1,'String',pwd)
see line 5,6,7 here fields in the structure handles are being used but i cannot see the structure being defined . How is this happening???????
NOTE :Please refer this link. If has the documentation of the example I am talking about http://in.mathworks.com/help/matlab/creating_guis/interactive-list-box-in-a-guide-gui.html#brbirpn
댓글 수: 0
답변 (1개)
Adam
2015년 4월 2일
A GUIDE-created UI will always have a handles structure embedded in it which is passed to every callback and which stores the handles to all UI components. You can also attacj your own data to handles if you want since it is always passed to callbacks to facilitate shared data in a GUI.
댓글 수: 2
Adam
2015년 4월 2일
Yes, but make sure you include the important line:
handles.answer = someFunction() % Whatever you want to store
guidata( hObject, handles )
That last line is what commits the handles structure back into the GUI. handles is simply a struct which is passed into the workspace of your callback function. i.e. it has function scope and any changes you make to it will simply be lost when the function exists if you do not include the guidata line at the end of your function.
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!