How do i determine a graph as a variable to then calculate euclidean distance?

1 view (last 30 days)
I need to use this formula
point1=[ time m h n v ]= finished(0.36,1.2);
point2=[ time m h n v ]= finished(0.3,0.86);
distance = norm(point1 - point2);
but I cannot 'name' the graphs in this way
  2 Comments
Walter Roberson
Walter Roberson on 28 Aug 2013
I do not understand what you mean by "name" a graph? Do you mean like title() ?
Which variable should be on your x axis in the graph? Which variable(s) should be on your y axis ?
Helen
Helen on 29 Aug 2013
No, I mean how do I 'name' the graph as a variable to then go on to calculate the distance between the graphs? For example, in the formula I need to name two points , as 'point1' and 'point2' but at the moment in order to get these two points I'm having to use the data cursor and line it up at exactly when X=60 in order to read off the y value. This is very time consuming so there must be a much quicker way.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 29 Aug 2013
I might be missing something in what you are asking.
It sounds to me as if you would like to plot some outputs (perhaps in a function you have no control over), and then treat the resulting lines as functions that can be arithmetically manipulated and evaluated at specific locations.
MATLAB stores its line graphics as a list of points, with X, Y, and potentially Z coordinates. The exact list of points must be supplied to the graphics call. The graphics call does not have any information about the function: it just gets the list of points. And the graphics always plots straight lines connecting adjacent points, never curves: the result can appear to be curved if the points are close together.
You can ask the graphics system to return the list of points for each line. But because the graphics system has not been given information about how the points relate to each other, the list of points is all that you get, not formulae. You cannot manipulate the results as formulae because they are not formulae, just list of points.
There is no possible routine that can take a list of points and convert it back to "the" formula the produced it. The most that can be done is to take a list of points and convert it to "a" formula that would produce the same list. Unless, that is, you can give MATLAB strong hints about the kind of formula that will be needed; for example you can get MATLAB to calculate the coefficients of a simple exponential a*exp(b*x) that would numerically best fit the list of points, but you have to tell MATLAB that is the shape you are looking for.
What you can do is get MATLAB to return the list of points, and then tell MATLAB to do interpolation (linear, cubic, spline, pchip, perhaps some others) of the points at the place you want to know the values.
g1x = get(LineHandle1, 'XData');
g1y = get(LineHandle1, 'YData');
g2x = get(LineHandle2, 'XData');
g2y = get(LineHandle2, 'YData');
y1_60 = interp(gix, g1y, 60, 'spline'); %spline interpolate at x = 60
y2_60 = interp(g2x, g2y, 60, 'spline'); %spline interpolate at x = 60
  2 Comments
Helen
Helen on 30 Aug 2013
Thank you for the help. I have tried using this formula but it says 'Undefined function or variable 'LineHandle1'.
Walter Roberson
Walter Roberson on 30 Aug 2013
Substitute the handle of one of the lines you are interested in for the place it says LineHandle1 .
If you are using plot() then the handles are outputs from that. For example,
LineHandle1 = plot(5:243, tanh(5:243));
If something out of your control drew the plots, then you can use findobj() to try to find the handles. See the documentation for that.

Sign in to comment.

Categories

Find more on 2-D and 3-D 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!