Matlab 绘制带有绘图和动态值的线

Matlab draw line with plot and dynamic values

我想在 matlab 应用程序设计器中用绘图画线。但我不知道如何创建行。我只是在新坐标上重新绘制点。

这是我的代码(函数每秒运行一次)(绘图格式为 plot(PlotUI,X,Y))

function function2(app)
    app.timeCounter = app.timeCounter + 1;
    plot(app.UIAxes,app.timeCounter,app.newValDblPublic);
end

如有任何帮助,我将不胜感激。

目前您只是绘制当前值集,如果您还想绘制历史值,则需要将它们保存在一个数组中并绘制整个数组。

%When the GUI is first created, start with one value in the array
app.time_values = [0];
app.y_values = [0];

%Inside your function
function function2(app)
    app.time_values(end+1) = app.time_values(end)+1; % Add a new value to the array, 1 greater than the last value
    app.y_values(end+1) = app.newValDblPublic;
    plot(app.UIAxes,app.time_values,app.y_values);
end