How to Rotate the Ellipses at calculated angle?

6 次查看(过去 30 天)
I am using the code as given below to calculate the ellipses and rotate by an angle. But it is not rotated at given angle. Can anyone please help me to resolve this issue?
%cov is 2x2 covariance matrix that is generated through a long process
t = 0:0:2*pi; %time axis
%Xest is center of ellipse and contain values of x and Y
%cov = 2x2 matrix
lambda = eig(cov);
[S, D] = eig(cov);
scale = 2.447; %for 95% confidense ellipse from sigma1
[a, a_i] = max(lambda); %find maximum eigenvalue
[b, b_i] = min(lambda); %find minimum eigenvalue
a = scale*sqrt(a); %scale according to confidence interval
b = scale*sqrt(b);
if cov(1,1) > cov(2,2) %resolve tilt of the ellipse
theta = atan2(S(2,a_i),S(1,a_i))
x_axis = a
y_axis= b
else
theta = atan2(S(2,b_i),S(1,b_i))
x_axis = b
y_axis = a
end
x = Xest(1) + x_axis*cos(t)*cos(theta) - y_axis*sin(t)*sin(theta);
y = Xest(2) + x_axis*cos(t)*sin(theta) + y_axis*sin(t)*cos(theta);
r = patch(x,y,'b');
  8 个评论
Image Analyst
Image Analyst 2020-6-18
Your code gives this:
Error using cov (line 46)
Not enough input arguments.
Error in test (line 6)
lambda = eig(cov);
Muhammad khan
Muhammad khan 2020-6-18
编辑:Muhammad khan 2020-6-18
if you use the covariance matrix i posted earlier you definetly get some results.

请先登录,再进行评论。

回答(1 个)

Rafael Hernandez-Walls
%cov is 2x2 covariance matrix that is generated through a long process
t = 0:0.1:2*pi; %time axis
%Xest is center of ellipse and contain values of x and Y
cov=[14.7813169401575 18.14084502625
18.140845026252 33.2623639805209];
Xest=[0 0];
%cov = 2x2 matrix
lambda = eig(cov);
[S, D] = eig(cov);
scale = 2.447; %for 95% confidense ellipse from sigma1
[a, a_i] = max(lambda); %find maximum eigenvalue
[b, b_i] = min(lambda); %find minimum eigenvalue
a = scale*sqrt(a); %scale according to confidence interval
b = scale*sqrt(b);
if cov(1,1) > cov(2,2) %resolve tilt of the ellipse
theta = atan2(S(2,a_i),S(1,a_i))
x_axis = a
y_axis= b
else
theta = atan2(S(2,b_i),S(1,b_i))
x_axis = b
y_axis = a
end
x = Xest(1) + x_axis*cos(t)*cos(theta) - y_axis*sin(t)*sin(theta);
y = Xest(2) + x_axis*cos(t)*sin(theta) + y_axis*sin(t)*cos(theta);
r = patch(x,y,'b');
  2 个评论
the cyclist
the cyclist 2020-6-18
OK, so this "answer" is just a recopying of OP's code, with the value of cov plugged in. Progress?
The following is the figure it produces. We continue to need more information from OP, about what the problem is. This ellipse looks nothing like the figure OP posted, so I find it impossible to give advice.
Muhammad khan
Muhammad khan 2020-6-18
编辑:Muhammad khan 2020-6-18
Ok i resolved it by myself. Thanks for all the comments and effort everyone did.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by