简体   繁体   English

(MATLAB)如何移动标绘点的原点?

[英](MATLAB) How can I move the origin of plotted points?

I wasn't sure how to word this question so please link me to any answer if this has been asked before. 我不确定如何措辞这个问题,因此,如果以前已经提出过这个问题,请把我链接到任何答案。

Let's say I have a graph with points making a line that starts at (5, 10) and goes to (10,10), but I want to move the points so that the first point starts at (0, 10) up to (5, 10). 假设我有一个图,其中的点的直线从(5,10)到(10,10),但我想移动这些点,以便第一个点从(0,10)一直到( 5、10)。 How do I go about doing this? 我该怎么做呢? Or what is this called so I can search on my own? 或这叫什么,以便我自己搜索? I still want the points to be the same distances apart relative to each other but with one of the points at a specific location that I specify. 我仍然希望这些点彼此之间的距离相等,但其中一个点位于我指定的特定位置。

Simply take all of your points, and subtract or add them by a certain amount to move the origin. 只需取所有点,然后减去或相加一定数量即可移动原点。 As such, because you want to move your line such that the horizontal component is shifted to the left by 5, you can just subtract every x co-ordinate by 5. 因此,由于您要移动线以使水平分量向左移动5,因此您只需将每个x坐标减去5。

As such, assuming your co-ordinates are in x and y , just do: 这样,假设您的坐标在xy ,请执行以下操作:

final_x = x - 5;
final_y = y;

Then go ahead and plot these values: 然后继续绘制以下值:

plot(final_x, final_y);

In general, if you want to move your points by a prescribed amount, do this: 通常,如果您想按规定的数量移动积分,请执行以下操作:

final_x = x + x_shift;
final_y = y + y_shift;

x_shift and y_shift would be the amount of movement you want the x and y co-ordinates to move. x_shifty_shift将是您希望xy坐标移动的移动量。 In this case, you want to move everything to the left by 5, and so x_shift = -5 and y_shift = 0 . 在这种情况下,您想将所有内容向左移动5,因此x_shift = -5y_shift = 0 If you want to move everything such that the origin is located at (0,0) , you would make x_shift and y_shift to be the minimum of the x and y values, or: 如果要移动所有东西,使原点位于(0,0) ,则应使x_shifty_shiftxy值的最小值,或者:

x_shift = min(x);
y_shift = min(y);

Using this will ensure that all of your points are with respect to (0,0) . 使用此方法将确保您的所有点都相对于(0,0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM