I have the Y co-ordinate to a very complex graph. How do I extract and plot the corresponding X coordinates?

19 views (last 30 days)
I can't generate the function of the graph because its too complex. I've plotted the graph using input data points. I have particular random values on the Y-axis and I need the corresponding X values. the find() function doesn't work because I think it only returns integral indices (Mine won't be an integral index).
  2 Comments
Image Analyst
Image Analyst on 21 May 2015
How did you plot it with only the Y data? If you don't have any x values, then of course it will just use the index as the x values. If you don't have the formula, then there is no way you can get any x other than the index. I mean, how could you possibly know what they are? Let's say I gave you Y = [34,56,83,155]. It will assume x = [1,2,3,4]. How could it possibly know that the x I was thinking of was [2,4,6,8]? Or maybe I was thinking x was really [4,13,25,68]. There's just no way of telling the x values at all, if all you have are the Y values and no equation or actual x data.
Samar Kenkre
Samar Kenkre on 21 May 2015
I do have X values that's how i plotted it, but I need a specific X value for a given Y value which isn't a part of my input data

Sign in to comment.

Answers (2)

quicklearner
quicklearner on 21 May 2015
If you have the plotted graph, then perhaps you can use the grabit.m filw ehich is available in the Matlab file exchange for free. It helps you extract data points from a graph.
All the best !

Star Strider
Star Strider on 21 May 2015
‘I do have X values that's how i plotted it, but I need a specific X value for a given Y value which isn't a part of my input data’
Assuming your data meets the requirements of the interpolation functions, I would use the interp1 function. To get an x for a specific y, this will likely work:
x_new = interp1(y, x, y_new)
with x and y the data you have, and y_new the data you want the corresponding x value (here x_new) for.
  3 Comments
Star Strider
Star Strider on 21 May 2015
One way is to force y to be monotonically increasing, then do the interpolation.
This works:
x = rand(1,10); % Create Data
y = rand(1,10); % Create Data
%
y_new = 0.5; % Known ‘y’ Value
[ys,yi] = sort(y); % Force ‘y’ To Be Monotonically Increasing
x_new = interp1(ys, x(yi), y_new);
%
figure(1)
plot(x, y, '+r')
hold on
plot(x_new, y_new, 'bp')
hold off
grid
Walter Roberson
Walter Roberson on 21 May 2015
If your y is not monotonic then you have the risk that asking to look up a particular y value would return multiple results.

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!