outerline of plot with multiple peaks?

1 回表示 (過去 30 日間)
Madan Kumar
Madan Kumar 2019 年 4 月 9 日
コメント済み: Adam Danz 2019 年 4 月 9 日
Hi,
I have a plot with multiple peaks (here, 2 peaks for simplicity and data is also attached). I want to plot the outerilne above the same plot. How can I do that? I tried using unique(x); but not getting the expected results,particularly the problem area (shown in figure). I Here is my code (I am using Matlab2018a),
a=importdata('abc.txt');
yyn=[a(:,2)' a(:,4)'];
bbn=[a(:,1)' a(:,3)'];
%using unique
[abn acn]=unique(bbn);
plot(a(:,1),a(:,2),'k')
hold on
plot(a(:,3),a(:,4),'k')
hold on
plot(abn,yyn(acn),'r')
Any help is appreciated. Thank you. xy.png
  2 件のコメント
Adam Danz
Adam Danz 2019 年 4 月 9 日
I'm having a hard time understanding your goal. Could you explain again? Also the code and the attached file do not reproduce the image you shared.
Madan Kumar
Madan Kumar 2019 年 4 月 9 日
編集済み: Madan Kumar 2019 年 4 月 9 日
I need to plot the outline of graph. Sorry, the last line is
plot(abn,yyn,'r').
I have also attached the data file. The outline plot should be like the 'red color (with unique value of x)' but without problem area (see above plot). The problem area should follow the blue line in above plot. Am I understood?

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

採用された回答

Adam Danz
Adam Danz 2019 年 4 月 9 日
編集済み: Adam Danz 2019 年 4 月 9 日
I'm going to go out on a limb and assuming you want to plot a line that overlaps the black curve until its end and then overlaps the blue curve from that point forward. This is what I understood in your question. If this isn't what you're looking for, let me know.
%import data
a=importdata('abc.txt');
% Plot 2 curves
plot(a(:,1),a(:,2),'k', 'LineWidth', 4)
hold on
plot(a(:,3),a(:,4),'b', 'LineWidth', 4)
% find index of bottom line that corresponds with the end of the upper line
[~, idx] = min(abs(a(:,3) - a(end,1)));
% Isolate the overlap coordinates and plot them
newX = [a(:,1); a(idx:end,3)];
newY = [a(:,2); a(idx:end,4)];
plot(newX, newY, 'r-', 'LineWidth',1.5)
  2 件のコメント
Madan Kumar
Madan Kumar 2019 年 4 月 9 日
Thank you so much. This is what I wanted.
Adam Danz
Adam Danz 2019 年 4 月 9 日
Great! Glad it worked out.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by