INTERPOLATED POINTS WHILE Plotting
10 views (last 30 days)
Show older comments
heir ancestors
on 6 Apr 2017
Commented: heir ancestors
on 6 Apr 2017
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162669/image.jpeg)
Hello everybody ;
I want to know that if there is any possibility to know all the graphs points in a matlab Plot.
What I mean by this : If I will plot a graph for given values of xx' axis for example [1:1:6]
Is there a possibility to know all the coordinates of the the graph ( in the example fx and fy) ?
here for example a short code :
A=(1:1:6);
fx=2.*cosd(A);
fy=100*sind(A);
figure(3)
plot(A,fx,'r.-')
hold on
plot(A,fy,'g.-')
legend('sinfunction','cosfunction')
the figure is showed as joined to this post ;
How to know all the coordinates of fx how to know all the coordinates of fy how to know the intersection poitns between fx and fy
2 Comments
Adam
on 6 Apr 2017
cosd and sind are how you know the intermediate points, but when you define a sample rate as you have done in A then this defines the accuracy with which you will see the results on the graph. You can increase the granularity of A to get more accuracy, but you will always have a discrete plot.
The intersection points can be estimated from the graph I suppose, but would seem to be more obviously calculated mathematically from the functions themselves.
Accepted Answer
John D'Errico
on 6 Apr 2017
Edited: John D'Errico
on 6 Apr 2017
Suppose you plot a line, as just two points, between (0,1) and (2,4).
h = plot([0 2],[1 4],'o-')
h =
Line with properties:
Color: [0 0 1]
LineStyle: '-'
LineWidth: 0.5
Marker: 'o'
MarkerSize: 6
MarkerFaceColor: 'none'
XData: [0 2]
YData: [1 4]
ZData: [1×0 double]
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/173763/image.jpeg)
You can now extract the points that you plotted.
h.XData
ans =
0 2
h.YData
ans =
1 4
But MATLAB does not allow you to extract all the points in between along that line segment. Of course, there are infinitely many of them. But even if your goal is to obtain the pixelated points along that line, you still cannot do so. Sorry.
Nothing stops you from using interpolation to obtain a set of interpolated points. interp1 will help you there. But that is all you can do.
Finally, it looks like you are looking to compute an intersection of two curves in a plot.
The simp[lest way to do this, if you have actual functions, is to use a tool like fzero. Subtract the functions, then solve for a zero point.
If you want to do this form data points, then use a tool like Doug Schwarz's intersections.m, available from the file exchange.
If you want to do it from a plot itself, then you need to extract the points from the plot, then use intersections on the extracted curves.
More Answers (0)
See Also
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!