How to plot a line over a specific interval?
조회 수: 21 (최근 30일)
이전 댓글 표시
I am attempting to plot cubic splines for 5 points. I have 4 functions to match each segment, but I only want the interval of the line that applies to that segment to appear on my plot.
I have these four lines:
plot (x,g(1))
plot (x, g(2))
plot(x, g(3))
plot(x, g(4))
They appear as so:
This is correct, but i want g1 to ONLY show from -1 to -.5. g2 to ONLY show from -.5 to 0, etc.
댓글 수: 0
채택된 답변
the cyclist
2020년 6월 29일
편집: the cyclist
2020년 6월 29일
Can you upload the data? Specifically, it is unclear to me what sort of data type g is.
Instead of plotting x, you'll want to do something like plotting
x(x>-1 & x<-0.5); % for g1
but I can't tell how to handle g1 without more info.
Also, it was unclear to me if the intervals are meant to be on x, or on g.
댓글 수: 3
추가 답변 (1개)
madhan ravi
2020년 6월 29일
ix = (g1 >= -1) & (g1 <= -.5); % follow the same for the rest
plot(x(ix), g1(ix))
댓글 수: 2
the cyclist
2020년 6월 29일
The fact that OP wrote
g(1)
rather than
g1
made me hesitate to suggest this solution. We'll see.
참고 항목
카테고리
Help Center 및 File Exchange에서 Scatter Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!