Finding values on a graph

1 Ansicht (letzte 30 Tage)
Andrew Wileman
Andrew Wileman am 13 Okt. 2015
Bearbeitet: dpb am 13 Okt. 2015
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

Antworten (1)

dpb
dpb am 13 Okt. 2015
Bearbeitet: dpb am 13 Okt. 2015
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 Kommentare
Andrew Wileman
Andrew Wileman am 13 Okt. 2015
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 am 13 Okt. 2015
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by