It looks like your x data never changes. That should mean your number of y points also remains constant. One thing to try is to just update the YData rather than creating a new plot.
As for how to stop it manually, you could attach a callback to your figure to detect either a key press or a click in an empty part of the figure window. You can read more about the available callbacks here. t3=linspace(0, 500, 2000);
y2=3*sin(0.5*x2-0.1*t3(1)-0.3);
fig = figure('Visible',"on",...
'KeyPressFcn',@keyPress, ...
'ButtonDownFcn',@buttonPress)
xlabel('x(m)','FontSize',15)
ylabel('y(t, x) (m)','FontSize',15)
y2=3*sin(0.5*x2-0.1*t3(i)-0.3);
function buttonPress(H,E)
Best Answer