PDA

查看完整版本 : Matlab轴缩放


poster
2019-12-10, 20:48
在循环内进行绘图时,如何精确地在Matlab绘图中获得固定的轴缩放比例?我的目的是看数据如何在循环内演化。我尝试使用运气好的axis manual和axis(...) 。有什么建议么?

我知道hold on这个问题,但是我不想看到旧数据。



回答:

如果要查看新的绘制数据替换旧的绘制数据,但保持相同的轴限制,则可以在循环中使用SET (http://www.mathworks.com/help/techdoc/ref/set.html)命令来更新绘制数据的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 (http://www.mathworks.com/help/techdoc/ref/hold.html)命令,因为您只是在更新现有的绘图对象,而无需添加新的对象。即使新数据超出轴限制,限制也不会改变。



更多&回答... (https://stackoverflow.com/questions/4086452)