How to clear this plot?

조회 수: 2 (최근 30일)
han han
han han 2020년 6월 22일
편집: Rik 2020년 6월 22일
As shown in the picture, what about the ellipse in the lower left corner?
My code wants to express that the size of the two ellipses can be changed by myself.
I want to present an ellipse and a regular circle.
xUECenter=5;
yUECenter=5;
a = 3;
b = 3;
r = a;
hEllipse = imellipse(gca,[-a, -b, 2*a, 2*b]);
disp(hEllipse);
xy = hEllipse.getVertices();
axesHandlesToChildObjects = findobj(gca, 'Type', 'line');
if ~isempty(axesHandlesToChildObjects)
delete(axesHandlesToChildObjects);
end
x = xy(:,1);
y = xy(:,2);
xy = [x y];
for k = 1 : length(angles_Panel_0)
theta = angles_Panel_0(k);
rotationArray = [cosd(theta) sind(theta); -sind(theta) cosd(theta)];
rotated_xy = xy * rotationArray;
xCenter2 = xUECenter + (r - 0.25) * cosd(theta);
yCenter2 = yUECenter + (r - 0.25) * sind(theta);
x = rotated_xy(:,1) + xCenter2;
y = rotated_xy(:,2) + yCenter2;
plot(x, y, 'b');
if k == 1
grid on;
hold on;
end
end
hold on;
xNodeCenter=6;
yNodeCenter=6;
a = 3;
b = 0.5;
r = a;
hEllipse1 = imellipse(gca,[-a, -b, 2*a, 2*b]);
xy = hEllipse1.getVertices();
axesHandlesToChildObjects = findobj(gca, 'Type', 'line');
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 = xy1 * rotationArray;
xCenter3 = xNodeCenter + (r - 0.25) * cosd(theta);
yCenter3 = yNodeCenter + (r - 0.25) * sind(theta);
x1 = rotated_xy(:,1) + xCenter3;
y1 = rotated_xy(:,2) + yCenter3;
plot(x1, y1, 'm');
if k == 1
grid on;
hold on;
end
end

채택된 답변

Rik
Rik 2020년 6월 22일
편집: Rik 2020년 6월 22일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by