Generate a sine wave that has no stop-time

1 Ansicht (letzte 30 Tage)
Ali Albaidhani
Ali Albaidhani am 23 Feb. 2022
Kommentiert: Ali Albaidhani am 23 Feb. 2022
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 Kommentar
Jan
Jan am 23 Feb. 2022
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 23 Feb. 2022
Bearbeitet: Jan am 23 Feb. 2022
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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by