Help using guidata in a script

1 view (last 30 days)
Julian
Julian on 30 Aug 2018
Commented: Julian on 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!

Accepted Answer

OCDER
OCDER on 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

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!