필터 지우기
필터 지우기

Generate a sine wave that has no stop-time

조회 수: 2 (최근 30일)
Ali Albaidhani
Ali Albaidhani 2022년 2월 23일
댓글: Ali Albaidhani 2022년 2월 23일
Hello everyone,
Im trying to generate a sine wave with matlab that has no stop time and can only be stopped manually.
I couldn't find any helpful solutions online, but im guess there will be a while loop that keeps increasing the stop time by one so it doesn't reach and end.
Here is an attempt from me, that has no success:-
f=5;
a=1;
Fs=1000
t1=1;
t=0 : 1/Fs :t1-1/Fs;
x=a*sin(2*pi*f*t)
figure(1)
plot(t,x)
while(1)
t1+1
end
Please tell me if im making a msitake with the while Loop or give me an alternative solution if you know one.
regards
Ali
  댓글 수: 1
Jan
Jan 2022년 2월 23일
The description "a sine wave with matlab that has no stop time" is vague.
Insie your loop you increase the value of t1, but nothing else happens. Do you expect to see something? Then you have to update the diagram.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2022년 2월 23일
편집: Jan 2022년 2월 23일
f = 5;
a = 1;
Fs = 1000;
t1 = 1;
figure;
while 1 % Runs until you press Ctrl-c
t = 0 : 1/Fs :t1-1/Fs;
x = a * sin(2 * pi * f * t);
plot(t, x);
drawnow; % Give Matlab a chance to display changes
t1 = t1 + 1;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by