Plotting piecewise, data from matrices/vectors
1 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Walter Roberson
2020-2-22
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 个评论
Walter Roberson
2020-2-24
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)];
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!