Select values on x axis corresponding to a y axis value

12 ビュー (過去 30 日間)
Darpan Verma
Darpan Verma 2019 年 3 月 12 日
コメント済み: Mauro Fusco 2019 年 3 月 12 日
Hi Everyone, I am trying to make a fit for the linear portion of the graph using MATLAB code, but I am stuck at this point.
I am trying to extract the value of x axis where the 10% line is made as shown in figure below. and extract x axis data where the 90% line is made. and that is defined by the variable parameter. Any help would be appreciated.
Screen Shot 2019-03-12 at 2.12.28 PM.png

採用された回答

Mauro Fusco
Mauro Fusco 2019 年 3 月 12 日
Let's say that your curve is described by the vectors x and y (I imagine that you obtain that curve via plot(x,y)).
Then you can find the maximum of the curve as:
y_max = max(y);
You can then pick the indices of the points corresponding to 10% and 90% of the maximum as:
idx_y10 = find(y == 0.1*y_max);
idx_y90 = find(y == 0.9*y_max);
The values that you are searching on the x axis will be:
x_10 = x(idx_y10);
x_90 = x(idx_y90);
I did not try it, enjoy!
  5 件のコメント
Darpan Verma
Darpan Verma 2019 年 3 月 12 日
Thanks I solved it. I was just doing a small error.
Thanks to both of you
Mauro Fusco
Mauro Fusco 2019 年 3 月 12 日
Very good, but it is correct that my answer was not fully precise. Therefore, I post here answer.jpga working code:
close all;
x = 0:0.01:3*pi/4;
y=sin(x);
plot(x,y);
[y_max,idx_max] = max(y);
idx_y10 = find(y > 0.1*y_max,1,'first');
idx_y90 = find(y(1:idx_max) < 0.9*y_max,1,'last');
x_10 = x(idx_y10);
x_90 = x(idx_y90);
hold on;
plot(x_10,0.1*y_max,'o red');
hold on;
plot(x_90,0.9*y_max,'o red');

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by