help required with scripts file

1 Ansicht (letzte 30 Tage)
Aaron Stronguin
Aaron Stronguin am 22 Apr. 2020
Bearbeitet: Walter Roberson am 22 Apr. 2020
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
  1 Kommentar
Rik
Rik am 22 Apr. 2020
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable. Your question is not urgent, the reason for that is explained here.
Have a read here and here. It will greatly improve your chances of getting an answer. You can find guidelines for posting homework on this forum here.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Deepak Gupta
Deepak Gupta am 22 Apr. 2020
Bearbeitet: Deepak Gupta am 22 Apr. 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

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by