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

12 visualizzazioni (ultimi 30 giorni)
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

Risposte (2)

Image Analyst
Image Analyst il 6 Giu 2018
Modificato: Image Analyst il 6 Giu 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 Commenti
Zoe Lee
Zoe Lee il 7 Giu 2018
Unfortunately, I would not be allowed to give that to you, as it is the core of my research, and uploading it here would jeopardize the integrity of my findings and future publications (i.e. if someone else comes here later, downloads, and uses it for their work).
Thank you all for your help! I've realized the viscircles command works better than the rectangle command for the scenario here, so I found a way around the initial problem. I should be ok without any more help.

Accedi per commentare.


Zoe Lee
Zoe Lee il 7 Giu 2018
When I do that, I get this output: Name Size Bytes Class Attributes
ball_rad 1x1 8 double
ball_rad_2 1x1 8 double
x_target 1x1 8 double
y_target 1x1 8 double
x_target =
22.7850
y_target =
25.4688
ball_rad =
0.4000
ball_rad_2 =
0.2000
And then the error, of course...

Categorie

Scopri di più su Fuzzy Logic in Simulink in Help Center e File Exchange

Prodotti


Release

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by