uicontrolでのCallbackの操作

8 views (last 30 days)
Mamoru Mabuchi
Mamoru Mabuchi on 20 May 2021
Commented: Mamoru Mabuchi on 20 May 2021
uicontrolを使って、ボタンが押されるまで処理を保留し、ボタンが押されたら処理を再開するスクリプトを作成したいです。
下記のスクリプトを作成してみましたが、思い通りの動作をしません。
どのようにスクリプトを記述すれば良いでしょうか、アドバイスお願いします。
fig = figure(1);
aaa = 0;
button = uicontrol(fig);
button.Callback = @ButttnFunction;
while aaa == 0
end
function ButttnFunction(src,event)
assignin('caller','aaa',1);
end

Answers (1)

Megumi Fukuda
Megumi Fukuda on 20 May 2021
Edited: Megumi Fukuda on 20 May 2021
「思い通りの動作をしません」というのは、figureが出てこない・ボタンを押せないということでしょうか。
whileの中身を以下のように変更してみてください。
while aaa == 0
disp('Button is not pressed yet')
pause(0.1);
end
pause(0.1)でwhileループの繰り返しの間に休みを入れています。ご自身の都合の良い数値に変えてみてください。
なお、GUIDEは将来的に削除される予定です。GUIDEでアプリを作成されている場合、AppDesignerへの移行をおすすめしております。詳細は以下をご覧ください。
GUIDE の移行策
https://jp.mathworks.com/help/matlab/creating_guis/differences-between-app-designer-and-guide.html
  1 Comment
Mamoru Mabuchi
Mamoru Mabuchi on 20 May 2021
解決いたしました。
ありがとうございました。

Sign in to comment.

Categories

Find more on GUIDE アプリの移行 in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!