# Generate a sine wave that has no stop-time

3 views (last 30 days)
Ali Albaidhani on 23 Feb 2022
Commented: Ali Albaidhani on 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
Jan on 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.

Jan on 23 Feb 2022
Edited: Jan on 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
Ali Albaidhani on 23 Feb 2022
than you so much Jan!