Why does plot(X,Y,'or') and plot(X,Y) give different results
1 次查看(过去 30 天)
显示 更早的评论
So,I have a set of points that I am trying to visualize.
The points are obtained by running the code mentioned in the below link
Basically the output of this is a structure that stores the positions of the edges along with some other stuff.
Now,when I plot edges.x and edges.y using the following command
plot(edges.x,edges.y,'or'); The result comes out like this
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/709742/image.jpeg)
Whereas the result of plot(edges.x,edges.y) is like this
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/709747/image.jpeg)
The original result of the code is as follows
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/709752/image.jpeg)
Any idea why the line plot is coming out like this,and what can be done to correct it.
Note 1 : After inspecting the picture,I was able to visually figure out the correct order.If you look at edges.mat the expected starting point is [103,66.3015] and the same is the end point
0 个评论
采纳的回答
Walter Roberson
2021-8-12
This is to be expected. There is nothing that requires that the algorithm returns the point is edge-tracing order.
You should use boundary() https://www.mathworks.com/help/matlab/ref/boundary.html to detect the order
idx = boundary(edge.x, edge.y);
plot(edge.x(idx), edge.y(idx))
4 个评论
Walter Roberson
2021-8-12
You might need to increase shrink even more (maximum 1.0)
However, if you look near the 45 level, you can see there the closest approach between the two distinct blobs. Now compare that distance to the size of the gap in the middle of the base near 78 or so: the base gap looks close to the same or possibly even larger. So one time you want the distance to be inconsequential not indicating a different object, but the other time you want the distance to indicate a new object.
I thought for a second that perhaps you could get somewhere by taking the two nearest neighbours of each point, but look again at the gap at the base. The second tick mark from the left, the pair of points close together: the two nearest neighbours to the right-hand one of the pair are both to the left.
ABCD EF GHIJ
the two nearest neighbours of F are D and E, not E and G. So nearest neighbour techniques in themselves are not going to be enough. Perhaps you could get somewhere with roughly the 5 nearest neighbours and some logic.
更多回答(2 个)
Chunru
2021-8-12
The line plot draws line from one point to another point. The order of points is thus important. The 'or' option just plots the data points without draw line.
If the data points were in right order, you could have seen a line plot more similar to the scatter plot ('ro').
0 个评论
KSSV
2021-8-12
When you plot with markers (i.e. 'o'), plot will not connect the markers. But when you simply plot, it will try to join them by lines. Your points are not in order, so they are joined as the points are given.
Attach your points to get what you want.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!