Plotting piecewise function over two periods
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to plot a piecewise function over two periods. I am able to plot it over two periods but it is not very efficient.
Below is the code I am using for now.
How do I make this more efficient/simpler? I am only using MATLAB, no additional softwares or extensions such as Symbolic Math Toolbox.
t0 = 0:0.001:(pi/10);
ih_t0 = 500*sin((10*t0)).^2;
subplot(2,1,1)
plot(t0, ih_t0,'b')
hold on
t1 = (pi/10):0.001:0.8;
ih_t1 = 0;
plot(t1,ih_t1)
hold on
t2 = 0.8:0.001:(0.8+(pi/10));
t3 = (0.8+(pi/10)):0.001:1.6;
plot(t2,ih_t0)
hold on
plot(t3,ih_t1)
hold off
댓글 수: 0
채택된 답변
Voss
2023년 10월 20일
t = 0:0.001:0.8;
ih = zeros(size(t));
idx = t < pi/10;
ih(idx) = 500*sin(10*t(idx)).^2;
plot([t t+0.8],[ih ih])
댓글 수: 0
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!