Push Button help!

19 ビュー (過去 30 日間)
Priyana Kumar
Priyana Kumar 2021 年 4 月 18 日
回答済み: Divija Aleti 2021 年 4 月 21 日
Hello, I am trying to make two push buttons in MATLAB in which one allows me to quit the program and the other allows me to continue running it.
This is what I have as my function:
function ButtonQuit
message = sprintf("Are you sure you would like to quit gesture recognition?");
figquit = uifigure('Position', [450 150 395 175]);
tarea = uitextarea(figquit);
tarea.Value = message;
%movegui('southeast')
%uialert(figquit,message,'Warning','Icon','warning');
% Create a push button %left bottom width height
btn1 = uibutton(figquit,'push',...
'Position',[50, 20, 150, 50],...
'ButtonPushedFcn', @(btn,event) Button1(btn1));
btn1.Text = 'Yes, Quit';
btn2 = uibutton(figquit,'push',...
'Position',[250, 20, 150, 50],...
'ButtonPushedFcn', @(btn,event) Button2(btn2));
btn2.Text = 'No';
if Button1(btn1) %if btn1, confirm quit
return;
elseif Button2(btn2) %if btn2, close window, continue gesture recognition
close(fig);
end
end
I'm not sure if something is missing or I have the wrong idea entirely.

回答 (1 件)

Divija Aleti
Divija Aleti 2021 年 4 月 21 日
Hi Priyana,
There is a slight change in syntax that you need to make for the ButtonPushedFcn.
Assuming that when Button 1 is pushed, nothing should happen, and when Button 2 is pushed, the figure should close, I corrected the syntax as follows :
function ButtonQuit
message = sprintf("Are you sure you would like to quit gesture recognition?");
figquit = uifigure('Position', [450 150 395 175]);
tarea = uitextarea(figquit);
tarea.Value = message;
%movegui('southeast')
%uialert(figquit,message,'Warning','Icon','warning');
% Create a push button %left bottom width height
btn1 = uibutton(figquit,'push',...
'Position',[25, 20, 150, 50],...
'ButtonPushedFcn', @(btn,event) Button1);
btn1.Text = 'Yes, Quit';
btn2 = uibutton(figquit,'push',...
'Position',[225, 20, 150, 50],...
'ButtonPushedFcn', @(btn,event) Button2);
btn2.Text = 'No'
function Button1(btn, event)
return;
end
function Button2(btn, event)
close(figquit);
end
end
If you need an example on how to create a quit button, have a look at the following link:
Hope this helps !
Regards,
Divija

カテゴリ

Help Center および File ExchangeProgramming Utilities についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by