Plotting piecewise, data from matrices/vectors

1 view (last 30 days)
This is how my plot looks.
Preferably it would look like this both in the start and in the end (for both red and blue).
I have tried to use:
P = [...]'; % The data for the blue one
pw = piecewise(cond1,val1,cond2,val2,...)
% P as val1
I want it to go straight down to 0 after the last 780, not gradually as seen in the first picture.
But I can't get it to work. Any suggestions as to how I could acheive this?

Accepted Answer

Walter Roberson
Walter Roberson on 22 Feb 2020
To go straight down, you need to duplicate the x coordinate with the two different y values.
stairs() automatically does the coordinate duplication, but it does it for all the points, which is not what you want, so you will need to duplicate the coordinate yourself.
Or you could add a second x coordinate that is marginally larger than the place you want to plunge; you would only be able to see the difference compared to duplicated coordinates if you zoomed way way in, but there are some cases such as interp1() where duplicated coordinates give you problems.
  3 Comments
Walter Roberson
Walter Roberson on 24 Feb 2020
If you know the index then
x = [x(1:idx), x(idx)+0.0001, x(idx+1:end)];
P = [P(1:idx), 0, P(idx+1:end)];

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!