How to translate figure so that point1 [0 -1]' is located at the origin?

조회 수: 1 (최근 30일)
I began by plotting the original figure with the following code:
% Define coordinates of original graph
point1 = [0 -1]';
point2 = [1 1]';
point3 = [3 2]';
point4 = [3 0]';
point5 = [2 -1]';
point6 = [0 -1]';
points = [point1 point2 point3 point4 point5 point6];
plot_points = @(list_of_points) plot(list_of_points(1,:), list_of_points(2,:), '-o');
% Plot characteristics
plot(points(1,:), points(2,:), 'b')
axis([-1 3.5 -1 2]) % axis min and max
grid on
xlabel('x-axis')
ylabel('y-axis')
title('2D Cad Figure')
What can be done to translate figure so that point1 is located at the origin?

채택된 답변

Star Strider
Star Strider 2019년 1월 16일
I am not certain what result you want.
One option is to add this line after the plot call:
axis(reshape([point1, point3]', 1, 4))
In context:
% Plot characteristics
plot(points(1,:), points(2,:), 'b')
axis([-1 3.5 -1 2]) % axis min and max
grid on
xlabel('x-axis')
ylabel('y-axis')
title('2D Cad Figure')
axis(reshape([point1, point3]', 1, 4))
  댓글 수: 2
MATLABhelp
MATLABhelp 2019년 1월 16일
Thanks for the reply, that is how the graph should look, but how would you plot both graphs on the same plot? The original plot, and the reshaped plot?
Star Strider
Star Strider 2019년 1월 16일
As always, my pleasure.
The plot is not reshaped. Probably a better way to define the axis limits is:
axis([min(points(1,:)) max(points(1,:)) min(points(2,:)) max(points(2,:))])
This produces the same plot, as does:
axis('tight')

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by