필터 지우기
필터 지우기

how do i prompt a prompt

조회 수: 2 (최근 30일)
stephen aboasu
stephen aboasu 2015년 9월 9일
답변: Image Analyst 2015년 9월 10일
I'm writing a code to do a calculation. after the user puts in the number I want the next line of code to ask the user is it in inches or centimeters.

답변 (2개)

Walter Roberson
Walter Roberson 2015년 9월 9일
consider using menu()
But if not then
whichunits = input('Inches (i) or centimeters (c)? ', 's');
if strncmpi(whichunits, 'i', 1)
whichunits = 'i';
elseif strncmpi(whichunits, 'c', 1)
whichunits = 'c';
else
warning('I did not understand that answer. Assuming inches');
whichunits = 'i';
end

Image Analyst
Image Analyst 2015년 9월 10일
Try this:
promptMessage = sprintf('Are the units inches or centimeters?');
titleBarCaption = 'Define Units';
buttonText = questdlg(promptMessage, titleBarCaption, 'in', 'cm', 'Cancel', 'in');
if strcmpi(buttonText, 'Cancel')
% User clicked cancel - they want to bail out
units = ''
return;
elseif strcmpi(buttonText, 'cm')
% User clicked cm. Assign a variable called "units".
units = 'cm'
else
% User clicked in. Assign a variable called "units".
units = 'in'
end

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by