Hi, I'm trying to plot an interval funciton, where f(x) = 1 from -1 <= x <= 0 and f(x) = -1 from 0 < x < 2, and f(x) = 0 otherwise. I'm not sure how to setup the intervals to do this.

 채택된 답변

KSSV
KSSV 2019년 4월 18일

0 개 추천

m = 500 ;
x = linspace(-1,3,m) ;
f = zeros(size(x)) ;
f(x>=-1 & x <=0) = 1 ;
f(x>=0 & x <2) = -1 ;
plot(x,f)

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Annotations에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2019년 4월 18일

답변:

2019년 4월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by