Plotting piecewise, data from matrices/vectors
조회 수: 3 (최근 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!