Correct use of isempty

6 ビュー (過去 30 日間)
Murphy Richard
Murphy Richard 2020 年 8 月 8 日
回答済み: Walter Roberson 2020 年 8 月 8 日
Hi all,
I am making a program that can degrees to radiens and vice versa. I'd like to know if I can use the isempty function in the manner below. If I have used it incorrectly, I would appreciate if you could tell me how to use it in the right manner.
I would also like some help with the switch case statement. I would like the user to input a 2 letter code to determine if he is to convert degrees to radients or radients to degrees (DR or RD). However the code cannot run , I would like to know how to solve my problem.
clc
prompt = 'Convert Degree to Radients or Radient to Degree?';
option = input(prompt, 's')
switch option
case DR
angleD=input('Enter angle in degrees');
if not isempty(angleD)
rad=degrees * pi / 180
x=fprintf('The angle is equal to %f radients',rad);
disp(x)
case RD
angleR=input('Enter angle in radients');
if not isempty(angleR)
deg=radians * 180 / pi
y=fprintf('The angle is %f degrees',deg);
otherwise
disp('invalid option')
end
P.S I am using octave online

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 8 月 8 日
clc
prompt = 'Convert Degree to Radients or Radient to Degree?';
option = input(prompt, 's')
switch option
case 'DR'
angleD=input('Enter angle in degrees');
if ~isempty(angleD)
rad=degrees * pi / 180
x=fprintf('The angle is equal to %f radients',rad);
disp(x)
case 'RD'
angleR=input('Enter angle in radients');
if ~isempty(angleR)
deg=radians * 180 / pi
y=fprintf('The angle is %f degrees',deg);
otherwise
disp('invalid option')
end

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by