How to plot stairstep between two line?

5 次查看(过去 30 天)
Source: Semantic Scholar
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.

采纳的回答

DGM
DGM 2021-5-16
编辑:DGM 2021-5-16
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 个评论
DGM
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])

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by