matlabplotlinematlab-app-designer

Matlab draw line with plot and dynamic values


I am trying to draw line with plot in matlab app designer. But i dont know how to create line. I am just redrawing point on new coordinates.

This is my code (functions runs each second) (format of plot is plot(PlotUI,X,Y))

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

I will be thankful for any help.


Solution

  • At the moment you are just plotting the current set of values, if you want to plot the historic values too, you need to keep them in an array and plot the entire array.

    %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