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);
But can you please give an example value of cov (maybe upload it in a MAT file), so that we can see the output that you see? (For me, some values of cov result in values of x and y that are imaginary, so only a straight line is plotted. For others, I see a tilted ellipse. I can tell if that is a problem with your code, or with what I am choosing as an input.)
Then, tell us what the problem is with your output, and what you expected instead. It's hard to help if we don't understand what the problem is better.
The code you have posted does not produce that figure. The code you posted creates a single ellipse. What that ellipse looks like depends on the value of cov, which have not reported to us.
Also, in the code provide, it seems that the ellipse is always at least approximately along the line x==y, where in the figure above the ellipse is always along the vertical.
Therefore we cannot guess why your code is not doing what expect. You simply have not given us all the information.
the above covariance matrix is used in first iteration and the same code is used to produce the ellipses in the loop. Tthe result is same as shown in figure attached above.
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.
Impossible de terminer l’action en raison de modifications de la page. Rechargez la page pour voir sa mise à jour.
Translated by
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.