How to Rotate the Ellipses at calculated angle?

7 visualizzazioni (ultimi 30 giorni)
Muhammad khan
Muhammad khan il 17 Giu 2020
Modificato: Muhammad khan il 18 Giu 2020
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 Commenti
Image Analyst
Image Analyst il 18 Giu 2020
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 il 18 Giu 2020
Modificato: Muhammad khan il 18 Giu 2020
if you use the covariance matrix i posted earlier you definetly get some results.

Accedi per commentare.

Risposte (1)

Rafael Hernandez-Walls
Rafael Hernandez-Walls il 18 Giu 2020
%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 Commenti
the cyclist
the cyclist il 18 Giu 2020
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 il 18 Giu 2020
Modificato: Muhammad khan il 18 Giu 2020
Ok i resolved it by myself. Thanks for all the comments and effort everyone did.

Accedi per commentare.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by