GUI Handles Visibility Different

6 ビュー (過去 30 日間)
CGN
CGN 2017 年 4 月 22 日
編集済み: Image Analyst 2017 年 4 月 22 日
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.

回答 (1 件)

Walter Roberson
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 件のコメント
CGN
CGN 2017 年 4 月 22 日
I have done this, but the handles structure still does not seem to be updating to include the new values.
Walter Roberson
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 ExchangeGraphics Performance についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by