I'm having issues with the rectangle function. The error statement I'm getting for the code below is: ''Error using rectangle: Value must be numeric'' and I can't figure it out. I'm trying to get a simulated UAV to a goalpoint, but it keeps stopping
10 views (last 30 days)
Show older comments
x=0;
filename='Zoe';
t=1000;
figure(1)
center=[0,0];
r=5;
ball_rad=0.4;
for count=1:1:10
%Vint=50+5.*rand(1,1)
loc_x=0;
loc_y=0;
loc_x=start_x;
Vres=Vself
clf;
x_target=20+10*rand(1,1)
y_target=20+10*rand(1,1)
rectangle('Position',[x_target-ball_rad_2,y_target -ball_rad_2, ball_rad_2*2, ball_rad_2*2],...
'Curvature',[1,1],...
'Facecolor','b');
for sdx=1:1:num_images
ball_rad=0.4;
rectangle('Position',[loc_x-ball_rad,loc_y-ball_rad,ball_rad*2,ball_rad*2],...
'Curvature',[1,1],...
'Facecolor','g');
fisr=readfis('Get_to_Goal')
distance_s=((loc_x-x_target)^2)+((loc_y-y_target)^2)
distance=sqrt(distance_s)
angle=atand(((y_target-loc_y))/(x_target-loc_x))
AnimationOutput=evalfis([distance angle],fisr)
r=distance*(sind(AnimationOutput(:,2)))
r2=distance*(cosd(AnimationOutput(:,2)))
if angle==0
if loc_x_previous==x_target
loc_x=x_target
loc_y=loc_y+r2*(loc_y-y_target)/(abs(y_target-loc_y))
elseif loc_y_previous==y_target
loc_y=y_target
loc_x=loc_x+r*(loc_x-x_target)/(abs(x_target-loc_x))
end
end
if loc_x>=x_target
loc_x=x_target
end
if loc_y>=y_target
loc_y=y_target
end
if y_target-loc_y<=0
angle=0;
if x_target-loc_x>0
loc_x=loc_x-r*0.5*(loc_x-x_target)/(abs(x_target-loc_x));
else
loc_x=loc_x-r*0.5*(loc_x-x_target)/(abs(x_target-loc_x));
end
end
axis([-22 42 -22 42]);
title('MC Goal')
drawnow;
%%most of the rest of the code is a video writer
0 Comments
Answers (2)
Image Analyst
on 6 Jun 2018
Edited: Image Analyst
on 6 Jun 2018
Right before the for loop, put these lines of code with no semicolons. Tell us what you see in the command window:
whos x_target ball_rad y_target ball_rad_2
x_target
y_target
ball_rad
ball_rad_2
12 Comments
See Also
Categories
Find more on Fuzzy Logic in Simulink 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!