# How to Rotate the Ellipses at calculated angle?

조회 수: 5 (최근 30일)
편집: 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이전 댓글 6개 표시이전 댓글 6개 숨기기
Image Analyst 2020년 6월 18일
Error using cov (line 46)
Not enough input arguments.
Error in test (line 6)
lambda = eig(cov);
편집: Muhammad khan 2020년 6월 18일
if you use the covariance matrix i posted earlier you definetly get some results.

댓글을 달려면 로그인하십시오.

### 답변 (1개)

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 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 2020년 6월 18일
Ok i resolved it by myself. Thanks for all the comments and effort everyone did.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by