![](/img/trans.png)
[英]Using fixedRate timer in MATLAB with different data for each interval (trying to replace for loop with timer)
[英]using timer inside a loop
我的GUI的目的是顯示圖像並獲得用戶的響應:按鍵(E或I)或無響應。 在圖像本身之間應該有3秒的暫停,以顯示一些文本(我的代碼中為a7 UIcontrol
)。 問題是我需要做30次,所以我使用了一個帶有計時器的循環。 但是GUI效果很差。
它應該執行以下操作:
for 30 times do
2 sec showing text (a7)
then showing an image for 3 sec or until I\E are pressed
end
這是我的代碼; 我要添加兩個版本,因為它們的主要區別在於TIMER函數和屬性。
https://docs.google.com/document/d/1N6LSDAYo_DVrBCUbuPth4JPCvkI3pBNcnAZcV6Kl9wM/edit
可讀性更高的版本: http : //pastebin.com/vd3HNGv1
和照片在這里(盡管您可以使用任意兩張照片): https : //picasaweb.google.com/alex.goltser/ScrapbookPhotos
起初,問題始終是一個錯誤:
您嘗試在計時器工作時啟動計時器
但是現在這是另一回事了。
為什么要運行計時器功能?
這是運行循環的另一種方式:
for repeat = 1:30
*show text*
drawnow %# to make sure the graphics are updated
pause(2) %# wait two seconds
*show image*
drawnow
t = tic;
done = false;
while ~done && toc(t)<3 %# checks for keypress or until 3 secs
*check for keypress*
if E/I key has been pressed
done = true;
end
end
end %# repeat 30x
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.