필터 지우기
필터 지우기

Plotting piecewise function over two periods

조회 수: 1 (최근 30일)
Yamana Uno
Yamana Uno 2023년 10월 20일
편집: Voss 2023년 10월 20일
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

채택된 답변

Voss
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개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by