update guidata when while loop of p pushbutton is running

2 views (last 30 days)
Hi, I am creating a GUI. I made the while loop by pressing a push button, it stops when the button is pressed again. Inside the loop, i should update guidata value, a flag set by another push button. How can i do that? Now the guidata is updated once i stop the while loop. Thanks

Answers (1)

Jan
Jan on 28 Feb 2013
If the data stored in the figure should be modified by the other button, modify them in the callback of the other button. Therefore the WHILE loop must contain a pause or drawnow, such that events (here the button-click) get a chance to be processed.
But if you update the data using GUIDATA after the WHILE loop is finished, it may overwrite the changes made by the button's callback. Therefore inside the loop the GUIDATA command must be used twice: once for loading and once for saving the changed values:
while Condition
current = guidata(FigureHandle); % Obtain current value
current.YourData = current.YourData + 1; % Update value
guidata(FigureHandle, current); % Store value
drawnow; % Let other events be processed
end

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!