如何对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
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

登录发表评论。

Accepted Answer

Ángel González
Ángel González 2018年8月23日
谢谢大家的帮助。正如您所说,问题是我如何存储坐标。@DPB的评论完美地恢复了问题: https://es.mathworks.com/matlabcentral/answers/416020-how-can-i-plot-points-in-matlab#comment_602802

更多答案(1)

Afshin Aghayan
Afshin Aghayan on 9 Oct 2019
您可以使用此代码以[x,y,f(x,y)]的形式显示任何数据或带有坐标的数据

Community Treasure Hunt

在Matlab Central中找到宝藏,发现社区如何为您提供帮助!

Start Hunting!