How do i determine a graph as a variable to then calculate euclidean distance?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
Walter Roberson
2013년 8월 28일
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 ?
답변 (1개)
Walter Roberson
2013년 8월 29일
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
Walter Roberson
2013년 8월 30일
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!