Correct use of isempty

4 views (last 30 days)
Murphy Richard
Murphy Richard on 8 Aug 2020
Answered: Walter Roberson on 8 Aug 2020
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

Answers (1)

Walter Roberson
Walter Roberson on 8 Aug 2020
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

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!