フィルターのクリア

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
  1 件のコメント
Ali Albaidhani
Ali Albaidhani 2022 年 2 月 23 日
than you so much Jan!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by