How to limit function output range?
조회 수: 10 (최근 30일)
이전 댓글 표시
Say I wan to create a sine wave between -4 to 4, all other values outside -4 and 4 will be zero.j
Here's the code that I thought it was going to work, but I am getting incorrect dimension, is there another way to achieve what I want to achieve?
t = [-10:0.1:10]
u1 = @(t) t>=4;
u2 = @(t) t<=4;
u3 = @(t) (u1(t) * u2(t));
x1 = @(t) ((10 * sin(pi*t/4)) * u3(t));
plot(t, x1(t));
plot(t, x1(-(t+2)/2));
댓글 수: 0
답변 (2개)
Matt J
2022년 8월 28일
Use element-wise multiplication.
u1 = @(t) t>=-4;
u2 = @(t) t<=4;
u3 = @(t) (u1(t) .* u2(t));
x1 = @(t) ((10 .* sin(pi*t/4)) .* u3(t));
fplot(x1,[-10,10])
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Parallel Computing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

