Ser*_*erg 5 matlab matlab-figure axis-labels
我需要创作一部电影.假设,我创建了一个轴并在其上绘制了一些非常自定义的东西:
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, ...);
Run Code Online (Sandbox Code Playgroud)
现在我运行一个循环,其中只y更新值.
for k = 1 : N
% y changes, update the axis
end
Run Code Online (Sandbox Code Playgroud)
使用new y(或x和y)更新轴的最快和最简单的方法是什么,保留所有轴属性?
一种快速的方法是简单地更新您绘制的数据的y值:
%# 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)
Run Code Online (Sandbox Code Playgroud)
编辑如果有多行,即lineHandle向量,该怎么办?您仍然可以一步更新; 但是,您需要将数据转换为单元格数组.
%# 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(:) );
Run Code Online (Sandbox Code Playgroud)