I have the Y co-ordinate to a very complex graph. How do I extract and plot the corresponding X coordinates?
22 次查看(过去 30 天)
显示 更早的评论
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 个评论
Image Analyst
2015-5-21
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.
回答(2 个)
quicklearner
2015-5-21
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 !
0 个评论
Star Strider
2015-5-21
‘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 个评论
Star Strider
2015-5-21
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
2015-5-21
If your y is not monotonic then you have the risk that asking to look up a particular y value would return multiple results.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!