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?
t = 0:0:2*pi;
lambda = eig(cov);
[S, D] = eig(cov);
scale = 2.447;
[a, a_i] = max(lambda);
[b, b_i] = min(lambda);
a = scale*sqrt(a);
b = scale*sqrt(b);
if cov(1,1) > cov(2,2)
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');