help required with scripts file

조회 수: 2 (최근 30일)
Aaron Stronguin
Aaron Stronguin 2020년 4월 22일
편집: Walter Roberson 2020년 4월 22일
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
Rik
Rik 2020년 4월 22일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Deepak Gupta
Deepak Gupta 2020년 4월 22일
편집: Deepak Gupta 2020년 4월 22일
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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by