필터 지우기
필터 지우기

Plotting piecewise, data from matrices/vectors

조회 수: 3 (최근 30일)
Jørgen Myklebust
Jørgen Myklebust 2020년 2월 22일
댓글: Jørgen Myklebust 2020년 2월 25일
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?

채택된 답변

Walter Roberson
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
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)];
Jørgen Myklebust
Jørgen Myklebust 2020년 2월 25일
Great! I do :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by