如果要查看新绘制的数据,请替换旧的绘制数据,但保持相同的轴限制,可以使用循环中的
SET命令更新绘制数据的x和y值.这是一个简单的例子:
hAxes = axes; %# Create a set of axes
hData = plot(hAxes,nan,nan,'*'); %# Initialize a plot object (NaN values will
%# keep it from being displayed for now)
axis(hAxes,[0 2 0 4]); %# Fix your axes limits, with x going from 0
%# to 2 and y going from 0 to 4
for iLoop = 1:200 %# Loop 100 times
set(hData,'XData',2*rand,... %# Set the XData and YData of your plot object
'YData',4*rand); %# to random values in the axes range
drawnow %# Force the graphics to update
end
当您运行上述操作时,您会看到一个星号在轴上跳转几秒钟,但轴限制将保持不变.您不必使用HOLD命令,因为您只是更新现有的绘图对象,而不是添加新的绘图对象.即使新数据超出轴限制,限制也不会改变.