why the square wave is just a line?
이전 댓글 표시
i'm trying to get a square wave graph for 5 cycles. but the plot is just a line
T = 2.25;
samples = 500;
t = linspace(-2.75,T,samples+1); % 5 cycles
t(end) = [];
s(-2.75 <= t < -0.25) = 1;
s(-0.25 <= t < 2.25) = -1;
N = 5;
s = repmat(s, [1 N]);
t = linspace(-2.75, N*T, N*samples + 1);
t(end) = [];
figure()
plot(t, s)
thanks
채택된 답변
추가 답변 (1개)
Jan
2018년 3월 25일
The problem is here:
s(-2.75 <= t < -0.25) = 1;
s(-0.25 <= t < 2.25) = -1;
The condition -2.75 <= t < -0.25 is evaluated from left to right:
- tmp = -2.75 <= t: This is either FALSE (0) or TRUE (1)
- tmp < -0.25: This is FALSE in every case, because neither 0 nor 1 are lower than -0.25.
You want:
s(-2.75 <= t & t < -0.25) = 1;
s(-0.25 <= t & t < 2.25) = -1;
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!