How can I create a button that says yes & no?

Hello, how can I create a yes & no button to a question that I want to prompt the user's answer to and then also store whether the user clicked yes or no?

回答 (4 件)

Geoff Hayes
Geoff Hayes 2014 年 12 月 2 日

2 投票

Hermione - try using questdlg to create a question with the yes or no answer. Something like
dlgTitle = 'User Question';
dlgQuestion = 'Do you wish to continue?';
choice = questdlg(dlgQuestion,dlgTitle,'Yes','No', 'Yes');
choice will be a string for 'Yes' or 'No'.
Image Analyst
Image Analyst 2014 年 12 月 14 日

2 投票

HC, regarding your followup question/comment, try this:
promptMessage = sprintf('Is Image Analyst awesome?');
titleBarCaption = 'Yes or No';
numberOfUsers = 4;
buttonSelections = zeros(1, numberOfUsers); % Preallocate.
for userNumber = 1 : numberOfUsers
button = questdlg(promptMessage, titleBarCaption, 'Yes', 'No', 'Yes');
if strcmpi(button, 'Yes')
buttonSelections(userNumber) = 1;
else
buttonSelections(userNumber) = -1;
end
end
% Report their choices to the command window:
buttonSelections
% Plot a bar chart
bar(buttonSelections);

2 件のコメント

HC
HC 2014 年 12 月 18 日
Hi Image Analyst, thank you for your input! However, what if I want to save the users' yes & no answer to a file for example an excel file and then extract this file onto a graph because the yes & no answers are only for x axis, y axis will be something completely different.
Image Analyst
Image Analyst 2014 年 12 月 20 日
You can use xlswrite(filename, {'Yes'}, 'A1') to save a "yes" to a file. You can use xlsread() to read it back in.

サインインしてコメントする。

Samantha Florimo
Samantha Florimo 2014 年 12 月 2 日

0 投票

question = menu('Whatever your question is?', 'Yes', 'No')
This will pop up as a little menu in which you can select yes or no as a button. The Yes values are stored as 1's and the No values are stored as 2's.
And then to store the answers you can store whether they selected 1 or 2 and find the data from there.

1 件のコメント

HC
HC 2014 年 12 月 13 日
Hi Samantha, thank you for your help! with your suggestion, how would I modify that so I can prompt multiple user's answers and store them separately? Because it seems like the second time I run it and click no as opposed to yes, it erased my yes input the first time. And also, how would i use all of these data i collected and make it to a graph?

サインインしてコメントする。

Deepesh B
Deepesh B 2014 年 12 月 2 日

0 投票

Hi
refer
button = questdlg('qstring','title','str1','str2',default)
in matlab help

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

質問済み:

HC
2014 年 12 月 2 日

コメント済み:

2014 年 12 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by