如何对MATLAB中的绘制点进行分类?
37 views (last 30 days)
显示较旧的评论
你好!我有一个关于绘图点的问题。在我的项目中,我得到了
X
and
y
coordinates and plotting them just when I read them from the socket, and I get something like this:
Just after plotting the coordinates I'm indexing them in two different vectors (one for
Xcoordinates
and the other for
ycoordinates
)。问题是,当我try to plot them again in another script (or in another figure) the result is not what I expected.
The code I use for plotting the points the second time is:
数字()
为了i = 1:1000%1000是x_vector和y__vector的长度
绘图(x_vector(i),y_vector(i),'o')
抓住on
轴([0 1920 0 1080]);
set(gca,'ydir',,,,'撤销',,,,'xaxislocation',,,,'最佳')
结尾
这是先前代码的结果:
I guess that the second time I try to plot the two vectors
阴谋
正在尝试通过一些回归打印一些线性函数,而不是打印我期望的点云。
Thank you
11条评论
dpb
2018年8月23日
That's calling sort repetitively every iteration...there's no indication of needing them sorted; if do, far more efficient to wait until done collecting and then sort the whole vector once.
当然,根据排序X的顺序保持和重新排序Y是必须保持两者之间的关联。
或者,一个人可以做
slightly
differently as
Xy=[];
whilecollecting()
% get x, y
Xy=[xy; [x y]];
...
结尾
Xy=sortrows(xy);
and will have x,y in two columns in the one arrray sorted by increasing x