Effacer les filtres
Effacer les filtres

Generate a sine wave that has no stop-time

2 vues (au cours des 30 derniers jours)
Ali Albaidhani
Ali Albaidhani le 23 Fév 2022
Commenté : Ali Albaidhani le 23 Fév 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 commentaire
Jan
Jan le 23 Fév 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.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 23 Fév 2022
Modifié(e) : Jan le 23 Fév 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

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by