Correct use of isempty

10 次查看(过去 30 天)
Murphy Richard
Murphy Richard 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 CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by