Help using guidata in a script

1 回表示 (過去 30 日間)
Julian
Julian 2018 年 8 月 30 日
コメント済み: Julian 2018 年 8 月 31 日
Hi everyone,
i have a quick question about the use of guidata.
Say i have a script like that:
random code [handles, movie] = timelapse(selection, handles] guidata(gcbo, handles) random code
do i really need to use guidata in this case or does my function already return the current handle structure? Thank you guys!

採用された回答

OCDER
OCDER 2018 年 8 月 30 日
If you pass handles as input and also output, you don't need guidata
Use guidata only to store/retrieve the GUI's data.
function [handles, movie] = myFcn(CurFigHandle)
handles = guidata(CurFigHandle); %In this case, use guidata to retrieve handles, since it was not an input
movie = handles.movie;
function [handles, movie] = myFcn(handles)
movie = handles.movie;
%No guidata required, since handles was passed as the input.
In GUIDE, the handles is pretty much always passed as the 3rd input to a callback function, so no need to use guidata to "retrieve" handle. You do need to use guidata to "store" any changes to handles though.
function pushbutton_callback(hObject, events, handles)
movie = handles.movie;
handles.movie = movie(1:end-1); %Changes made!
guidata(hObject, handles); %save modified handles
  1 件のコメント
Julian
Julian 2018 年 8 月 31 日
Thank you, that was very helpful!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by