Problem with 2D plotting

조회 수: 6 (최근 30일)
Orion
Orion 2015년 9월 1일
댓글: Star Strider 2015년 9월 1일
I have the following graph:
but what I need is for all 3 lines to stop at y=2, and not continue any further.
How could I do that?

채택된 답변

Star Strider
Star Strider 2015년 9월 1일
You didn’t post your code, so I can only offer you the most obvious solution. Put this line just below the plot call in your code:
axis([xlim 0 2])
  댓글 수: 2
Star Strider
Star Strider 2015년 9월 1일
Nebojsa’s Answer moved here:
Ah yes, that was silly of me. Here's the code:
EDU>> x=[0,10,120];
EDU>> a=1/30*x;
EDU>> b=3/4*a;
EDU>> c=1.5*b;
EDU>> plot(x,a,x,b,x,c)
Star Strider
Star Strider 2015년 9월 1일
This works:
x = linspace(0, 120);
a=1/30*x;
b=3/4*a;
c=1.5*b;
plot(x(a<=2),a(a<=2), x(b<=2),b(b<=2), x(c<=2),c(c<=2))
Experiment to get the result you want.
This approach uses ‘logical indexing’ to limit the plots. See Using Logicals in Array Indexing for a full explanation.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Networks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by