image
image

Reputation: 173

Is there any way to get all points which was drawin on matlab plot

Hi I was wondering if there is any way to get all points which was drawn on Matlab plot. Let's say that I drawn one line on plot and to draw this line I used just two points - matlab ploter connected these points and I get a line. Is there any way to get all the points which are on that line, without saving this plot to file ??

Upvotes: 1

Views: 1228

Answers (2)

KnowledgeBone
KnowledgeBone

Reputation: 1663

You can generate the points you are looking for through basic linear regression. Feed in your x and y variables to Matlab's regression function and it calculates the coefficients of the line of plot(x,y). With the line equation set up, you can feed in a list of new x variables and it will calculate the corresponding y values.

x=[x1; x2];
y=[y1; y2];
b = regress(y,[ones(length(x),1) x])
new_y=b(1)+b(2)*[new_x1:new_x2]

Upvotes: 0

Jonas
Jonas

Reputation: 74940

If you plot a line from two points, e.g. plot([x1 x2],[y1 y2]), the easiest way to get all the plots on the line is to calculate them directly.

nPts = 100; %# number of points on the line you want

%# listOfPoints is a 2-by-nPts array with all the points on the line
listOfPoints = [x1:(x2-x1)/(nPts-1):x2;y1:(y2-y1)/(nPts-1):y2];

Upvotes: 1

Related Questions