Thank you all for helping me. As you said, the problem was how I was storing the coordinates. This comment from @dpb resumed the problem perfectly: https://es.mathworks.com/matlabcentral/answers/416020-how-can-i-plot-points-in-matlab#comment_602802
How to sort points for plotting in MATLAB?
26 views (last 30 days)
Hello! I've got a little question about plotting points. In my project, I'm getting 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 x coordinates and the other for y coordinates). The problem is, when I 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:
for i=1:1000 %1000 is the length of x_vector and y_vector
plot(x_vector(i), y_vector(i), 'o')
axis([0 1920 0 1080]);
set(gca, 'ydir', 'reverse', 'xaxislocation', 'top')
And this is the result of the previous code:
I guess that the second time I try to plot the two vectors plot is trying to print some linear function through some regression instead of printing the cloud of points I expect.
More Answers (1)
Afshin Aghayan on 9 Oct 2019
you can use this code for displaying any data in the form of [x, y, f(x,y)] or data with coordinate