I know a certain y1 and I want to find the respective x1.

1 回表示 (過去 30 日間)
roberta perna
roberta perna 2019 年 6 月 14 日
コメント済み: James Browne 2019 年 6 月 15 日
I have a graph where x and y are two vectors.
plot(x,y)
I know a certain y1 and I want to find the respective x1.
thanks

回答 (4 件)

Torsten
Torsten 2019 年 6 月 14 日
x1 = fzero(@(z)interp1(x,y,z)-y1,1)
  2 件のコメント
darova
darova 2019 年 6 月 14 日
sorry, it works
darova
darova 2019 年 6 月 14 日
It's difficult to choose intial condition:
x = linspace(0,3,10);
y = x.^2;
y1 = 4;
x1 = fzero(@(z)interp1(x,y,z)-y1,1)
plot(x,y,x1,y1,'or')

サインインしてコメントする。


darova
darova 2019 年 6 月 14 日
I'd use polyxpoly or intersections
x = linspace(0,10,20);
y = sin(x);
y1 = 0.6; % find x at y=0.6
xc = [min(x) max(x)]; % boundaries of horizontal line
yc = [y1 y1];
[x1,y1] = polyxpoly(x,y,xc,yc);
plot(x,y,'.-b')
hold on
plot(xc,yc,'.-g')
plot(x1,y1,'or')
hold off

roberta perna
roberta perna 2019 年 6 月 14 日
Sorry not work.
  1 件のコメント
darova
darova 2019 年 6 月 14 日
What doesn't work? What did you try?

サインインしてコメントする。


James Browne
James Browne 2019 年 6 月 15 日
編集済み: James Browne 2019 年 6 月 15 日
Greetings,
I believe I have a solution to your problem, I wrote a scrip to demonstrate the concept, let me know if this is not what you are looking for and I will try to find a better solution. Here you go:
close all
clear
clc
%set arbitrary values of x, x can be any set of inputs to y(x)
x = [ 1 2 3 4 5 6 7 ];
%generate an arbitrary set of values y(x), y(x) can be any function
y = 2*x;
%Select a known, arbitrary value fromthe y-vector, y1
y1 = y(randi(length(y)))
%Now we first find the index of the value y1
idx = find( y == y1)
%Since every entry in the y-vector is dependant on a corrosponding entry in
%the x-vector, we can use the index value of y1 to find the corrosponding
%value in the x-vector ( x1 ) as follows:
x1 = x(idx)
plot(x,y,x1,y1,'kd')
title('y = f(x) and (x1, y1)')
ylabel('y(x)')
xlabel('x')
legend('y = f(x)','(x1, y1)','location','southeast')
  2 件のコメント
darova
darova 2019 年 6 月 15 日
Im afraid it doesn't work
James Browne
James Browne 2019 年 6 月 15 日
I somehow messed up on the upload, I corrected the previous answer, it should work now.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by