This error keeps popping up and I have no idea why: Error using viscircles Expected input number 1, centers, to be real. Error in viscircles​>validateC​entersAndR​adii (line 283) validateat​tributes(c​enters,{'n​umeric'},{​'nonsparse​','real', ... Erro

I am trying to do an animation for a linkage system and it is not plotting one of the links for some reason.
P1_pos = [56.25;43.1];
P2_pos = [56.25-A*cos(theta);43.1-A*sin(theta)];
P4_pos = C*[0;1];
P5_pos = D*[0*sin(theta);-1+1*sin(theta)]; %P5_pos = D*[0;-1+sin(theta)];
E = sqrt(A^2 + D^2 - 2*A*D*cos(theta));
a = asin(A*sin(theta)./E);
b = acos(E.^2 + C^2 - B^2)./(2*E*C);
P3_pos = [C + B*cos(a+b); B*sin(a+b)];
P5x = P5_pos(1,:);
P5y = P5_pos(:,1);
P5vx = diff(P5x);
P5vy = diff(P5y);
P5v = sqrt(P5vx.^2 + P5vy.^2);
ani = subplot(2,1,1);
P1_pos_cir = viscircles(P1_pos',0.05);
P2_pos_cir = viscircles(P2_pos(:,i)',0.05);
P3_pos_cir = viscircles(P3_pos(:,i)',0.05);
P4_pos_cir = viscircles(P4_pos',0.05);
P5_pos_cir = viscircles(P5_pos(:,i)',0.05);

6 Comments

Don't put message in title...truncated error message.
We can't test as don't have constants but the obvious problem is that one (or more) of your Px_pos values is complex. E is the most likely culprit it would appear.
Use the debugger and see what is going on...
Here are the constant values
A = 8.25; %in
B = 48;
C = 42;
D = 20;
t = 0:0.01:20; %sec
omega = 5.0265; %rad/sec
theta = omega*t;
and this is the full error message:
Error using viscircles
Expected input number 1, centers, to be real.
Error in viscircles>validateCentersAndRadii (line 283)
validateattributes(centers,{'numeric'},{'nonsparse','real', ...
Error in viscircles>parseInputs (line 245)
[centers, radii] = validateCentersAndRadii(centers, radii, first_string);
Error in viscircles (line 115)
[ax, centers, radii, options] = parseInputs(varargin{:});
Error in ME450_project_linkage (line 35)
P3_pos_cir = viscircles(P3_pos(:,i)',0.05);
P3_pos_cir = viscircles(P3_pos(:,i)',0.05);
Is this inside a loop of the construct for i = 1:n ?
I don't see a for statement here, and i is default to sqrt(-1) in matlab, unless you reassign it.
Yeah, I noticed that too, but that's using i as an array index which would be another error on indexing must be real and positive...

Sign in to comment.

 Accepted Answer

You did not give us any values to test with for A, B, C, D
E = sqrt(A^2 + D^2 - 2*A*D*cos(theta));
Looks like the area of a triangle with sides A and D and angle theta between them. The area of a triangle is often greater than 1 but depending on the values of the variables could also be small < 1.
a = asin(A*sin(theta)./E);
A*sin(theta)./E can end up greater than 1, leading to asin() of a value greater than 1, which is complex valued. Everything gets messy from that point

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!