How to run a for loop one at a time with each button click?
9 ビュー (過去 30 日間)
Keerthana Natarajan 2022 年 11 月 8 日
コメント済み: Keerthana Natarajan 2022 年 11 月 9 日
I have a for loop within a uicontrol-defined button. The for loop has to run 3 times, however it runs all the three loops together when the button is pushed once. How can I run the loop one at a time with every button click?
I have the chunk of code pasted here
set(messaget1g1,'String',sprintf('Collect $%d and pay a fine of $%d',...
datat1g1.Button_Pressed(i)='A'; %Data collection but need for loop
datat1g1.Earned(i)=gettrialone(r1(i)); %Data collection but need for loop
datat1g1.Fee(i)=paytrialone(r2(i)); %Data collection but need for loop
回答 (1 件)
Jim Riggs 2022 年 11 月 8 日
At the end of your "for" loop, add a "while" loop that looks for the button value.
if i < 3 (you don't want it to pause the last time)
(get button_status) % I don't know the exact commands for this
This will cause it to loop indefinitely until the button is pressed.
Make sure that the button status is reset inside the for loop.
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!