How can I create a button that says yes & no?
조회 수: 163 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (4개)
Geoff Hayes
2014년 12월 2일
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'.
댓글 수: 0
Image Analyst
2014년 12월 14일
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
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
2014년 12월 2일
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.
Deepesh B
2014년 12월 2일
Hi
refer
button = questdlg('qstring','title','str1','str2',default)
in matlab help
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!