help required with scripts file
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
How do I get my script to display "Invalid input" whenever a user inputs a value less than zero or greater than 90 degrees? I need some help with this please
%%
%script file
h=figure;
clf(h);
AxesH = axes('NextPlot','add');
while (1)
play = menu('Welcome. Do you want to play?: ', 'Yes', 'No');
switch play
case (1)
b = input('Please input angle value: ');
if b >= 0 || b <=90
[x,y] = HDTask1function_f(b);
z = rand()*3.5;
j = z+0.5;
hndl2=plot([z j],[0 0],'LineWidth',5);
hold on
set(gca,'Xlim',[0 4])
set(gca,'Ylim',[0 4])
hndl=plot(x(1),y(1),'r.','MarkerSize',50);
for ii=2:length(x)
drawnow;
set(hndl,'XData', x(ii), 'YData', y(ii));
pause(0.0025);
if y(ii:end) < 0
y(ii:end) = 0;
pause(0.5);
if x(1,ii) > z && x(1,ii) < j
disp('You gained a point');
end
break
end
end
elseif b < 0 || b >90
disp('Invalid input. Please input an angle in the range of [0 - 90]');
break
end
case(2)
disp('Thankyou for visiting')
break;
end
end
%%
%function file
function [x,y]=HDTask1function_f(a)
x0=0;
y0=1.8;
v0=4;
g=9.8;
t=0:0.01:5;
x=x0+v0*cos(a*(pi./180)).*t;
y=y0+v0*sin(a*(pi./180)).*t-(g.*t.^2)/2;
end
Respuestas (1)
Deepak Gupta
el 22 de Abr. de 2020
Editada: Deepak Gupta
el 22 de Abr. de 2020
Hello Aaron,
Change your code according to below lines, it should work.
if (b >= 0) && (b <=90)
%put your code here
else
disp('Invalid input. Please input an angle in the range of [0 - 90]');
break
end
Thanks,
Deepak
0 comentarios
Ver también
Categorías
Más información sobre Startup and Shutdown 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!