필터 지우기
필터 지우기

how to plot a piecewise function?

조회 수: 2 (최근 30일)
Leonardo Wayne
Leonardo Wayne 2016년 5월 5일
편집: Stephen23 2016년 5월 5일
I am trying to plot the function below using the following code but it is not correct. help?
  댓글 수: 1
Stephen23
Stephen23 2016년 5월 5일
편집: Stephen23 2016년 5월 5일
@Mohammad Abdalnasir Khalid Al-Hiyali: Please do not paste images of code: paste the code as text and then format it correctly using the {} Code button.

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

답변 (1개)

Star Strider
Star Strider 2016년 5월 5일
It would be best for you to copy your code, paste it to yout Question, and then use the {}Code button to format it.
You can replace your entire if block by one statement that multiplies a logical-index vector by the values of the function in that region. Use this assignment to ‘y’ instead:
y = (x<0.5).*(m*x+b) + ((x>=0.5) & (x<30.5)).*(upper_limit_y) + (x>30.5).*(-m*x+b);
I tested it and it works.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by