Inputting Units

14 ビュー (過去 30 日間)
Kevin
Kevin 2012 年 2 月 12 日
I have a user inputting different units for temperature. However, I only want the program to be able to accept Capital letters, so if they put a lowercase, it would tell them to input it again. What would be the code for this? I have something like this right now. The while part needs fixing.
Unit = input('Enter the units of the inputted temperature:','s'); while Unit == c Unit == k Unit == f Unit == r Unit = input('Please enter the unit with a Capital Letter:','s'); end

採用された回答

Image Analyst
Image Analyst 2012 年 2 月 12 日
That's not user friendly. It would be very annoying to your users and I recommend you DON'T DO THAT, especially since it's not necessary at all. Just convert what they input to upper case with the upper() function, like this:
% Set up the dialog box parameters
prompt = {'Enter temperature:','Enter the temperature scale:'};
dialogTitle = 'Enter parameters';
numberOfLines = 1;
defaultAnswers = {'100','C'};
userResponse = inputdlg(prompt, dialogTitle, numberOfLines, defaultAnswers);
% Extract out individual variables from the user response.
temperature = str2double(userResponse{1})
% Convert to upper case.
EoSI = upper(userResponse{2})
  4 件のコメント
Image Analyst
Image Analyst 2012 年 2 月 12 日
Possibly a better option is to use menu() to allow them to pick ONLY one of the allowed options.
Kevin
Kevin 2012 年 2 月 12 日
I got the idea of using the if/elseif/else block but I'm just unsure of how to actually go about it

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by