Getting intermediate points created by plot () in MATLAB

I have a series of pairs of XY points in MATLAB. These pairs describe the points around the figure in the image; they are not a function, which means that for each value of x two or more y-points can exist.

I can build these points individually using something like

plot(B(:,1),B(:,2),'b+'); 

I can also use a graph to connect the dots:

 plot(B(:,1),B(:,2),'r'); 

What I'm trying to extract are my own point values, which I can use to connect the points in order to use them for further analysis. I don't need a fully connected graph, and I need something data-based, not just the graphical image that plot () creates. I would really like plot () to generate these points (as if this was happening behind the scenes), but I tried to use the linseries returned by plot (), and it either does not work, as I understand it, or just does not give me what I want to.

I think it was an interpolation problem, but the dots do not contain a function; they describe the form. Essentially, all I need is the points that plot () apparently calculates; straight lines connecting a series of points. The curve will be a bonus and save me from grief.

How to do it in MATLAB?

Thanks!

Edit: Yes, the image will help :)

The blue dots are the actual values โ€‹โ€‹of the points (x, y) constructed using the first call to plot () above. The red outline is the result of calling the graph () using the second approach above. I am trying to get red point data; in other words, dots connecting the blue dots. alt text

+4
source share
3 answers

Adrien definitely has the right idea : determine the parametric coordinate, then perform linear interpolation along the x and y coordinates separately.

One thing I would like to add is another way to determine your parametric coordinate so that you can create evenly distributed interpolation points across the entire shape in one pass. The first thing you want to do if you have not done so already is to make sure that the last coordinate point is reconnected to the first, replicating the first point and adding it to the end:

 B = [B; B(1,:)]; 

Then, calculating the total distance between subsequent points, then taking the cumulative sum, you can get a parametric coordinate that takes small steps for points close to each other and larger steps for points remote from each other:

 distance = sqrt(sum(diff(B,1,1).^2,2)); %# Distance between subsequent points s = [0; cumsum(distance)]; %# Parametric coordinate 

Now you can interpolate a new set of points that are evenly distributed along the edge along the straight lines connecting your points using the INTERP1Q function:

 sNew = linspace(0,s(end),100).'; %'# 100 evenly spaced points from 0 to s(end) xNew = interp1q(s,B(:,1),sNew); %# Interpolate new x values yNew = interp1q(s,B(:,2),sNew); %# Interpolate new y values 

These new point sets will not necessarily include starting points, so if you want to make sure that the starting points also appear in the new set, you can do the following:

 [sAll,sortIndex] = sort([s; sNew]); %# Sort all the parametric coordinates xAll = [B(:,1); xNew]; %# Collect the x coordinates xAll = xAll(sortIndex); %# Sort the x coordinates yAll = [B(:,2); yNew]; %# Collect the y coordinate yAll = yAll(sortIndex); %# Sort the y coordinates 


Example:

Here is an example showing how this code is executed (I use 11 pairs of x and y coordinates, one of which is repeated for a complete example):

 B = [0.1371 0.1301; ... %# Sample data 0.0541 0.5687; ... 0.0541 0.5687; ... %# Repeated point 0.0588 0.5863; ... 0.3652 0.8670; ... 0.3906 0.8640; ... 0.4090 0.8640; ... 0.8283 0.7939; ... 0.7661 0.3874; ... 0.4804 0.1418; ... 0.4551 0.1418]; %# Run the above code... plot(B(:,1),B(:,2),'b-*'); %# Plot the original points hold on; %# Add to the plot plot(xNew,yNew,'ro'); %# Plot xNew and yNew 

alt text

+6
source

I would first determine some parametric coordinate along different segments (i.e. between data points)

 s = 1:size(B,1); 

Then just use interp1 to interpolate in s space. For example, if you want to create 10 values โ€‹โ€‹on the line between data points 5 and 6:

 s_interp = linspace(5,6,10); % parametric coordinate interpolation values x_coord = interp1(s,B(:,1),s_interp,'linear'); y_coord = interp1(s,B(:,2),s_interp,'linear'); 

That should do the trick.

a.

+2
source

Actually there is MATLAB function "improfile", which can help you with your problem. Suppose these are the 4 coordinates you want to find between these coordinates.

 xi=[15 30 20 10]; yi=[5 25 30 50]; figure; plot(xi,yi,'r^-','MarkerSize',12) grid on 

enter image description here

Just create a random image and run the function

 n=50; % total number of points between initial coordinates I=ones(max([xi(:);yi(:)])); [cx,cy,c] = improfile(I,xi,yi,n); hold on, plot(cx,cy,'bs-','MarkerSize',4) 

enter image description here

Hope this helps

0
source

Source: https://habr.com/ru/post/1332263/


All Articles