Finding values on a graph

6 次查看(过去 30 天)
Andrew Wileman
Andrew Wileman 2015-10-13
编辑: dpb 2015-10-13
Hi, Hoping someone may be able to help. I'm plotting two data sets on a graph (see attached). What I would like to do is find the point on the x-axis that corresponds to the last data point plotted on each graph and subtract them. e.g.y(x2(end))-y(x1(end)). I need to find the distance between the points on the x axis. Every time I try to do it as a function of y(x), Matlab says 'Attempted to access X_hat(0.0210118); index must be a positive integer or logical'
Thanks in advanced,
Andrew

回答(1 个)

dpb
dpb 2015-10-13
编辑:dpb 2015-10-13
If you plotted the two graphs, you already have the values; why isn't it simply
dyEnd = y2(end) - y1(end); % ??
In
y(x2(end))-y(x1(end))
you've used the x magnitude at the end of the two arrays as an index; you simply want (it would appear) the same two y points which I'd assume given you use x1 and x2 the y data are similarly in y1 and y2
If that's not it; 'splain further...
ADDENDUM If it's deltaX instead (and I guess it is on relooking at the pitchur and your followup below, then simply as mention in comment take the y() off the expression you already had--
dxEnd=x2(end)-x1(end);
  2 个评论
Andrew Wileman
Andrew Wileman 2015-10-13
Hi dpb, I see what you're getting at, I think. I want to find the corresponding value on the x axis, given the end y data point from each graph and then take the two away from each other. E.g. if y1(end) =0.021 say, the point x1 on the x axis = 50 say and if y2(end) = 0.023 say, x2 = 100. I want x2-x1, 100-50. Is that possible to do, or I'm I over complicating this? Thanks, Andy
dpb
dpb 2015-10-13
Seems to me the latter, yes. If you have the data with which to draw the graph, actually the graph itself is totally immaterial. It's simply
dxEnd = x2(end)-x1(end);
end here is the Matlab language element that is mult-valued by context; it serves as the conditional condition or function terminator but as an element of an array addressing expression it magically returns the last position in the array to which the index refers. In the above it has two values despite being the same function.
Again, if are meaning locations other than those of the data curves themselves, that's another issue but as you've described it you already have all the information needed.
Again, if that doesn't answer the question, try again. In that case, attach a short section of the two arrays (only four or five points from each is enough to illustrate as long as the values include a few at the beginning and end of each; that'll be enough to illustrate and for which you can show the precise values and the desired result.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by