Help using guidata in a script

1 Ansicht (letzte 30 Tage)
Julian
Julian am 30 Aug. 2018
Kommentiert: Julian am 31 Aug. 2018
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!

Akzeptierte Antwort

OCDER
OCDER am 30 Aug. 2018
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 Kommentar
Julian
Julian am 31 Aug. 2018
Thank you, that was very helpful!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by