I need to create a movie. Suppose, I create an axis and plot on it something very customized:
figure;
ax = plot(x, y, 'linewidth', 3, 'prop1', value1, 'prop2', value2, ...);
grid minor;
axis(ax, [xmin xmax ymin ymax]);
legend(ax, ...);
xlabel(ax, ...);
ylabel(ax, ...);
title(ax, ...);
Now I run a loop, where only the values of y
are being updated.
for k = 1 : N
% y changes, update the axis
end
What is the fastest and easiest way to update the axis with new y
(or x
and y
), keeping all the axis properties?
To change the units, set the FontUnits property. MATLAB automatically scales some of the text to a percentage of the axes font size. Titles and axis labels — 110% of the axes font size by default. To control the scaling, use the TitleFontSizeMultiplier and LabelFontSizeMultiplier properties.
Link the plot to the workspace variables by setting the data source properties of the plotted object to 'x2' and 'y2' . Then, update x2 and y2 in a for loop. Call refreshdata and drawnow each iteration to update the plot based on the updated data.
axis tight sets the axis limits to the range of the data. axis fill sets the axis limits and PlotBoxAspectRatio so that the axes fill the position rectangle.
limmethod = zlim("method") returns the current z-axis limits method, which can be 'tickaligned' , 'tight' , or 'padded' . limmode = zlim("mode") returns the current z-axis limits mode, which is either 'auto' or 'manual' . By default, the mode is automatic unless you specify limits or set the mode to manual.
A fast way is to simply update the y-values of the data you've plotted:
%# note: plot returns the handle to the line, not the axes
%# ax = gca returns the handle to the axes
lineHandle = plot(x, y, 'linewidth', 3, 'prop1', value1, 'prop2', value2, ...);
%# in the loop
set(lineHandle,'ydata',newYdata)
EDIT What if there are multiple lines, i.e. lineHandle
is a vector? You can still update in one step; you need to convert the data to a cell array, though.
%# make a plot with random data
lineHandle = plot(rand(12));
%# create new data
newYdata = randn(12);
newYcell = mat2cell(newYdata,12,ones(1,12));
%# set new y-data. Make sure that there is a row in
%# newYcell for each element in lineH (i.e. that it is a n-by-1 vector
set(lineHandle,{'ydata'},newYcell(:) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With