How to Rotate the Ellipses at calculated angle?

6 ビュー (過去 30 日間)
Muhammad khan
Muhammad khan 2020 年 6 月 17 日
編集済み: Muhammad khan 2020 年 6 月 18 日
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
Rafael Hernandez-Walls 2020 年 6 月 18 日
%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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by