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

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

Antworten (2)

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 Kommentare

I realized I had cleared out ball rad 2 from my initial inputs. When I put that in, then it gave me undefined x_target and y_target. When I defined those outside the for loop, I'm still getting this:
Error using rectangle: Value must be numeric. Is it a possible trigonometric error? I did account for that in my code, but perhaps I missed something.
Can you answer my question? Please put those lines of code in and let me know what it says.
Are you using symbolic variables anywhere? What is showing up for
class([loc_x-ball_rad,loc_y-ball_rad,ball_rad*2,ball_rad*2])
Image Analyst, I thought I had. Sorry if I wasn't clear enough. When I put in those lines of code, it said that "ball_rad_2 was undefined".I fixed that problem. Then it said "x_target is undefined" and "y target is undefined", I fixed that, and it gave me "Error using rectangle: Value must be numeric" as I stated above.
Walter, I am not using symbolic variables, and when I use the code you gave me, it gives me 'double'.
Experimenting, I just found that viscircles doesn't give me the error that rectangle does, but I am still kind of curious on what the major difference is.
No, those lines of code are supposed to come even before rectangle() is even executed. So what do they say?
That was before "rectangle" was executed. I'm not sure what else to tell you....
I appreciate your help though! If it's a bit too frustrating... I'll attempt to solve my issue with viscircles.
@Zoe Lee: Can you please upload the complete code by clicking the paperclip button.
There's the complete code. There are a lot of comments that only make sense to myself, but it's all there.
I get this:
To use 'readfis', the following product must be licensed, installed, and enabled:
Fuzzy Logic Toolbox
Error in test4 (line 64)
fisr=readfis('Get_to_Goal')
So I've added the Fuzzy Toolbox to the product list in the upper right of this screen.
Also, you had the lines in there before rectangle() but you had a % in front of them all which means they were commented out. Not sure why you did that but when I uncommented them I get this:
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 =
28.4071725598366
y_target =
22.5428217897153
ball_rad =
0.4
ball_rad_2 =
0.2
And it works for the first two calls to rectangle(). After that however, you call the fuzzy function and I can't continue. So you're just going to have to put these lines immediately before each call to rectangle:
clc;
whos x_target ball_rad y_target ball_rad_2
x_target
y_target
ball_rad
ball_rad_2
and see what happens. Tell us what you see in the command window right before rectangle() throws the error.
I need your Get_to_Goal.fis to test.
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.

Melden Sie sich an, um zu kommentieren.

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...

Kategorien

Mehr zu Fuzzy Logic in Simulink finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2017a

Gefragt:

am 6 Jun. 2018

Kommentiert:

am 7 Jun. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by