GUI Handles Visibility Different
조회 수: 12 (최근 30일)
이전 댓글 표시

Please see the attached image. I'm using the handles structure to pass values between a GUI and a main m file, but the variables I've created disappear when I try to access them in the main file, while I am able to access the other handles with the different icon. I'm not sure why I'm unable to access the last two variables.
댓글 수: 0
답변 (1개)
Walter Roberson
2017년 4월 22일
After you change the contents of the handles structure, be sure to use
guidata(hObject, handles)
where hObject is the name of the first parameter to your function (GUIDE tends to name it hObject)
댓글 수: 2
Walter Roberson
2017년 4월 22일
If you are running a routine, and a different routine updates handles, then that does not update the handles in the first routine.
For example, you might have a pushbutton that starts a plotting loop
function do_plotting(hObject, event, handles)
while handles.keep_going
do some plotting
drawnow()
end
and you might have a pushbutton
function stop_plotting(hObject, event, handles)
handles.keep_going = false;
guidata(hObject, handles);
that is intended to tell the loop to stop.
But "handles" is not a global structure. What gets passed in to a routine is a copy of the handles structure as of the time the routine starts. The guidata() in stop_plotting updates the master copy of the handles structure but does not affect the copy that is local to the do_plotting function.
If you are running a routine and you have reason to expect that some other routine might have updated handles and you need to see the updated version, then you need to use guidata() to retrieve the updated copy:
function do_plotting(hObject, event, handles)
while true
handles = guidata(hObject); %pull in current version
if ~handles.keep_going; break; end
do some plotting
drawnow()
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!