Return to "input" after error message
Show older comments
Hello everyone, I'm new using Matlab. I am generating a function in which the user has to enter some input values with "input (' ')", and if these values are not what is desired, it returns an error. What I want to do is that if it returns an error, instead of closing the function and starting again from the beginning, go back to the sentence "input (' ')". This is part of my code:
disp('INTRODUZCA EL VALOR DE LA DECLINACIÓN')
Dg=input('Grados de la declinación del astro (con signo - si es negativo): ');
if Dg==-90 || Dg==90
D=Dg;
elseif Dg<-90 || Dg>90
error('Valores mal introducidos. El valor de los grados debe estar entre -90 y 90')
else
Dm=input('Minutos de la declinación del astro: ');
if Dm<0 || Dm>59
error('Valores mal introducidos. El valor de los minutos debe estar entre 0 y 59')
end
Ds=input('Segundos de la declinación del astro: ');
if Ds<0 || Ds>59
error('Valores mal introducidos. El valor de los segundos debe estar entre 0 y 59')
end
if Dg<0
D=-(abs(Dg)+Dm/60+Ds/3600);
elseif Dg>=0
D=Dg+Dm/60+Ds/3600;
end
endFor example, if I make a mistake when entering the seconds (Segundos), re-enter them instead of closing the function, as I show below
Grados de la declinación del astro: -15 Minutos de la declinación del astro: 35 Segundos de la declinación del astro: 100 Error using FunctionName (line **) Valores mal introducidos. El valor de los segundos debe estar entre 0 y 59 Segundos de la declinación del astro:
Thanks.
Accepted Answer
More Answers (0)
Categories
Find more on Polar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!