I want to plot (filter) the highest value among both y1, y2.

1 回表示 (過去 30 日間)
omran alshalabi
omran alshalabi 2022 年 9 月 4 日
コメント済み: omran alshalabi 2022 年 9 月 4 日
I have this graph; I want to plot the highest value among both y1, y2. if blue line is highest want to plot the blue line. if red line is highest want to plot the red line.
I use this code, plot(x1, y1, x2, y2);

採用された回答

Chunru
Chunru 2022 年 9 月 4 日
% Generate some data
x1 = sort(rand(50, 1));
y1 = randn(size(x1)) + 0.4;
x2 = sort(rand(50, 1));
y2 = randn(size(x2)) + 0.3;
plot(x1, y1, 'r', x2, y2, 'b')
xmin = min([x1; x2]);
xmax = max([x1; x2]);
xq = linspace(xmin, xmax, 1000);
hold on
% Interpolation and max
y1q = interp1(x1, y1, xq, 'linear', 'extrap');
y2q = interp1(x2, y2, xq, 'linear', 'extrap');
plot(xq, max(y1q, y2q), 'k', 'LineWidth', 2);
legend("y1", "y2", "max", "Location", "Best")
  1 件のコメント
omran alshalabi
omran alshalabi 2022 年 9 月 4 日
Thank you,
it is solved the issue.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by