You should probably make your code into a function instead of copy-pasting it. That would highlight that you didn't define angles_Panel_0 or angles and used xy1 where you probably meant xy.
It would also show you that you forgot to do
delete(hEllipse1)
So the ellipse is still there.
You can use the code below, although you should add documentation for that function, and you should expain what you code is doing with comments.
angles_Panel_0=0;
xUECenter=5;
yUECenter=5;
a = 3;
b = 3;
r = a;
LineSpec='b';
plot_ellipse(a,b,r,xUECenter,yUECenter,angles_Panel_0,LineSpec)
angles=0;
xNodeCenter=6;
yNodeCenter=6;
a = 3;
b = 0.5;
r = a;
LineSpec='m';
hold on;
plot_ellipse(a,b,r,xNodeCenter,yNodeCenter,angles,LineSpec)
hold off;
function plot_ellipse(a,b,r,xNodeCenter,yNodeCenter,angles,LineSpec)
%write documentation here explaing inputs and usage
hEllipse = imellipse(gca,[-a, -b, 2*a, 2*b]); %#ok<IMELLPS>
xy = hEllipse.getVertices();
delete(hEllipse)
x = xy(:,1);
y = xy(:,2);
xy = [x y];
for k = 1 : length(angles)
theta = angles(k);
rotationArray = [cosd(theta) sind(theta); -sind(theta) cosd(theta)];
rotated_xy = xy * rotationArray;
xCenter = xNodeCenter + (r - 0.25) * cosd(theta);
yCenter = yNodeCenter + (r - 0.25) * sind(theta);
x = rotated_xy(:,1) + xCenter;
y = rotated_xy(:,2) + yCenter;
plot(x, y, LineSpec);
if k == 1
grid on;
hold on;
end
end
end