How to plot stairstep between two line?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示

Hello everyone. I currently writing a codes for EXIT chart. I've created the curves, and now i want to create the stairstep between two curves. How to plot it so the stairs doesn't cross the other curves, and what is the method to do that? Thank you.
採用された回答
I've never had to do this before, but this is what I came up with.
% just some similarly-shaped curves
x = linspace(0.1,1,10);
a = x.^0.2;
b = x.^0.3;
plot(x,a); hold on
plot(x,b,'k:');
xs = x(1);
ys = a(1);
n = 1;
while ~isnan(xs(n)) && n<100
xs(n+1) = interp1(b,x,ys(n));
ys(n+1) = interp1(x,b,xs(n+1));
ys(n+2) = interp1(x,a,xs(n+1));
xs(n+2) = interp1(a,x,ys(n+2));
n = n+2;
end
% if loop walks off the end of a non-converging dataset
xs = xs(~isnan(xs));
ys = ys(~isnan(ys));
% if the curves don't converge, bring the line to the x-limit
if xs(end) < x(end)
xs = [xs x(end)];
ys = [ys ys(end)];
end
plot(xs,ys,'b')
If the curves always converge, then some of this could be removed. Note the use of interp1 makes sure the plots touch even if the resolution is low. If the goal here is to count the number of steps or something, you'll have to figure that out. I just picked some arbitrary limit of 100.

7 件のコメント
Hello DGM, thank you for the answer. Seems like your codes above have three different input, but mine have four different input. Lets say it's:
plot(x,a); hold on
plot(y,b,'k:');
What should i modify from your codes above? Thank you
Jenjen Ahmad Zaeni
2021 年 5 月 16 日
編集済み: Jenjen Ahmad Zaeni
2021 年 5 月 16 日
something like this
p = linspace(0, 1, 100);
der_lambda = ((3/10)*p+(4/10)*p.^3)
q = 0.5.*der_lambda
q2 = linspace(0, 1, 100);
der_omega=(1-q2).^3
p2 = 1-der_omega
iavnd=1-p %x1
ievnd=1-q %y1
iecnd=1-p2 %x2
iacnd=1-q2 %y2
axis([0 1 0 1])
plot(iavnd,ievnd,'linewidth',1.5,'color','red','LineSmoothing','on')
hold on
plot(iecnd,iacnd,'linewidth',1.5,'color','black','LineSmoothing','on')
grid on
DGM
2021 年 5 月 16 日
You can adapt it like so
p = linspace(0, 1, 100);
der_lambda = ((3/10)*p+(4/10)*p.^3)
q = 0.5.*der_lambda
q2 = linspace(0, 1, 100);
der_omega=(1-q2).^3
p2 = 1-der_omega
iavnd=1-p %x1
ievnd=1-q %y1
iecnd=1-p2 %x2
iacnd=1-q2 %y2
xs = iavnd(end);
ys = ievnd(end);
n = 1;
while ~isnan(xs(n)) && n<100
xs(n+1) = interp1(iacnd,iecnd,ys(n));
ys(n+1) = interp1(iecnd,iacnd,xs(n+1));
ys(n+2) = interp1(iavnd,ievnd,xs(n+1));
xs(n+2) = interp1(ievnd,iavnd,ys(n+2));
n = n+2;
end
axis([0 1 0 1])
plot(iavnd,ievnd,'linewidth',1.5,'color','red','LineSmoothing','on')
hold on
plot(iecnd,iacnd,'linewidth',1.5,'color','black','LineSmoothing','on')
grid on
plot(xs,ys,'b')

Jenjen Ahmad Zaeni
2021 年 5 月 17 日
Thank you very much! It works perfectly with any other curves.
Hello again DGM. Sorry, but i have some problem here. I change the curve equation like this:
der_lambda = ((66*p)+(147*p.^2)+(72*p.^3))/285;
der_omega = ((62*(1-q2).^61)+(68*(1-q2).^67)+(77*(1-q2).^76)+(78*(1-q2).^77))/285;
And this is my program
p = linspace(0, 1, 1000);
der_lambda = ((66*p)+(147*p.^2)+(72*p.^3))/285;
q = 0.032.*der_lambda;
q2 = linspace(0, 1, 1000);
der_omega=((62*(1-q2).^61)+(68*(1-q2).^67)+(77*(1-q2).^76)+(78*(1-q2).^77))/285;
p2 = 1-der_omega;
iavnd=1-p; %x1
ievnd=1-q; %y1
iecnd=1-p2; %x2
iacnd=1-q2; %y2
xs = iavnd(end);
ys = ievnd(end);
n = 1;
while ~isnan(xs(n)) && n<100
xs(n+1) = interp1(iacnd,iecnd,ys(n));
ys(n+1) = interp1(iecnd,iacnd,xs(n+1));
ys(n+2) = interp1(iavnd,ievnd,xs(n+1));
xs(n+2) = interp1(ievnd,iavnd,ys(n+2));
n = n+2;
end
plot(iavnd,ievnd,'linewidth',1.5,'color','red','LineSmoothing','on')
hold on
plot(iecnd,iacnd,'linewidth',1.5,'color','black','LineSmoothing','on')
hold on
plot(xs,ys,'linewidth',2,'color','blue','LineSmoothing','off')
hold off
grid on
xlabel('I_{A,VND}, I_{E,CND}');
ylabel('I_{E,VND}, I_{A,CND}');
title('EXIT Chart','fontweight','bold','fontsize',12);
axis([0 1 0.9 1])
And here is the plot without xs and ys:

When i run the code, there are error like this:
Error using griddedInterpolant
The grid vectors are not strictly monotonic increasing.
Error in interp1 (line 183)
F = griddedInterpolant(X,V,method);
Error in exit_fix (line 22)
ys(n+1) = interp1(iecnd,iacnd,xs(n+1));
From the image above, it appears that from 0 to 0.9, has the value of 0. I've plot a tight plot before this and your codes works perfectly, but right now seems have an error. I don't really understand but i think it is because the plot has much zeros before it curved. Do you know how to fix it? Thank you so much for your help.
DGM
2021 年 5 月 29 日
You're right. The region where iecnd is zero corresponds to a vertical region in the curve. The interpolation doesn't work there. It's outside the plot area, so it can just be trimmed off.
p = linspace(0, 1, 1000);
der_lambda = ((66*p)+(147*p.^2)+(72*p.^3))/285;
q = 0.032.*der_lambda;
q2 = linspace(0, 1, 1000);
der_omega=((62*(1-q2).^61)+(68*(1-q2).^67)+(77*(1-q2).^76)+(78*(1-q2).^77))/285;
p2 = 1-der_omega;
iavnd=1-p; %x1
ievnd=1-q; %y1
iecnd=1-p2; %x2
iacnd=1-q2; %y2
% trim vectors where curve is vertical (it's outside the plot region anyway)
% if you need these variables for something else later, just make a copy
mk = iacnd>=0.85;
iecnd = iecnd(mk);
iacnd = iacnd(mk);
xs = iavnd(end);
ys = ievnd(end);
n = 1;
while ~isnan(xs(n)) && n<100
xs(n+1) = interp1(iacnd,iecnd,ys(n));
ys(n+1) = interp1(iecnd,iacnd,xs(n+1));
ys(n+2) = interp1(iavnd,ievnd,xs(n+1));
xs(n+2) = interp1(ievnd,iavnd,ys(n+2));
n = n+2;
end
plot(iavnd,ievnd,'linewidth',1.5,'color','red','LineSmoothing','on')
hold on
plot(iecnd,iacnd,'linewidth',1.5,'color','black','LineSmoothing','on')
hold on
plot(xs,ys,'linewidth',2,'color','blue','LineSmoothing','off')
hold off
grid on
xlabel('I_{A,VND}, I_{E,CND}');
ylabel('I_{E,VND}, I_{A,CND}');
title('EXIT Chart','fontweight','bold','fontsize',12);
axis([0 1 0.9 1])
Jenjen Ahmad Zaeni
2021 年 5 月 30 日
It works. Thank you very much again!
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で 2-D and 3-D Plots についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
