How to plot stairstep between two line?

1 view (last 30 days)
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.

Accepted Answer

DGM
DGM on 16 May 2021
Edited: DGM on 16 May 2021
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 Comments
Jenjen Ahmad Zaeni
Jenjen Ahmad Zaeni on 30 May 2021
It works. Thank you very much again!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by