unable to plot diagram in MATLAB
이전 댓글 표시
can anybody help me plotting the diagram below in Matlab (just one of them; the colorful one)?

I wrote the code below but the result isn't same.
clc;clear;close all;
t=linspace(0,5,100);
for i=1:length(t)
if (i>=0) && (i<0.5) ;
zp1(i)=0;
else if (i>=0.5) && (i<2.5);
zp1(i)=0.05*sin(2*pi*i);
else if i>=2.5 ;
zp1(i)=0;
end
end
end
end
plot(t,zp1)
답변 (1개)
Cris LaPierre
2021년 2월 17일
편집: Cris LaPierre
2021년 2월 17일
1 개 추천
Work on creating a sin wave that generates the amplitude and frequency you need first. Once you have that, set all y values corresponding to t<0.5 and t>2.5 to zero.
댓글 수: 4
Tina M
2021년 2월 18일
Cris LaPierre
2021년 2월 18일
Can you first create a sin wave with 0.05 amplitude and period of 2 seconds?
Tina M
2021년 2월 20일
Let's work with sin only. You are on to something here.
y2=@(t) -0.05*sin(2*pi*t);
Have you realized that a sine wave repeats every
seconds? If I want it to repeat every 2 seconds, I can just multiply t by π, making t at 2 seconds
.
seconds? If I want it to repeat every 2 seconds, I can just multiply t by π, making t at 2 seconds
.t=linspace(0,5,100);
y = 0.05*sin(t*pi);
plot(t,y)
A sin wave crosses the x axis at sin(0). You want that to haen at t=0.5. You can adjust the zero crossing by adding or subtracting to t. For example, x=t+0.5 will now move sin(0) to x=0.5.
Put that all together and you get
plot(t+0.5,y)
grid on
카테고리
도움말 센터 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


