Plotting piecewise, data from matrices/vectors
1 view (last 30 days)
Show older comments
Jørgen Myklebust
on 22 Feb 2020
Commented: Jørgen Myklebust
on 25 Feb 2020
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/273164/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/273165/image.png)
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?
0 Comments
Accepted Answer
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
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)];
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!