Correct use of isempty
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Walter Roberson
el 8 de Ag. de 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 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!