Correct use of isempty
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposte (1)
Walter Roberson
il 8 Ago 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
0 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!