update a plot with new data in matlab

To update a plot with new data in matlab, you can use the handle to the plot object and set the 'XData' and 'YData' properties of the plot to the new data. Here is an example:

main.m
% Generate some initial data
x = 1:10;
y = rand(1, 10);

% Plot the initial data and obtain the handle to the plot object
h = plot(x, y);

% Generate some new data
new_x = 1:10;
new_y = rand(1, 10);

% Update the plot with the new data
set(h, 'XData', new_x, 'YData', new_y);
276 chars
14 lines

This will update the plot with the new data without creating a new plot and without changing any other properties of the plot.

related categories

gistlibby LogSnag