2010-11-03 22 views
8

¿cómo se obtiene una escala fija de los ejes en el gráfico de Matlab cuando se traza dentro de un ciclo? Mi objetivo es ver cómo los datos están evolucionando dentro del ciclo. Intenté usar axis manual y axis(...) sin suerte. ¿Alguna sugerencia?Escalamiento de ejes de Matlab

hold on hace el truco, pero no quiero ver los datos anteriores.

+2

Es posible que también desee leer sobre la función no documentada 'LimInclude': http://undocumentedmatlab.com/blog/plot-liminclude-properties/ – Amro

Respuesta

6

Si desea ver sus nuevos datos representados sustituyen a los antiguos datos representados, pero mantener los mismos límites de los ejes, se puede actualice los valores xey de los datos graficados usando el comando SET dentro de su ciclo. Aquí está un ejemplo sencillo:

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 

Al ejecutar lo anterior, verá un salto asterisco en torno a los ejes de un par de segundos, pero los límites ejes permanecerá fijo. No tiene que usar el comando HOLD porque solo está actualizando un objeto de trazado existente, sin agregar uno nuevo. Incluso si los nuevos datos se extienden más allá de los límites de los ejes, los límites no cambiarán.

+4

+1 También tengo un par de sugerencias: 1) para evitar el parpadeo, debe habilitar el doble almacenamiento en búfer 'set (gcf, 'DoubleBuffer', 'on')'. 2) si desea aumentar la velocidad de dibujo y obtener una animación más suave, establezca la propiedad 'EraseMode' en algo distinto de 'normal' (usaría' xor' en este caso). Por supuesto, tendrá que usar funciones de bajo nivel como línea, parche, texto, etc. Consulte esta guía para obtener más detalles: http://www.mathworks.com/support/tech-notes/1200/1204. html # Section% 2023 – Amro

1

Debe establecer los límites de los ejes; Lo ideal es hacerlo antes de comenzar el ciclo.

Esto no funcionará

x=1:10;y=ones(size(x)); %# create some data 
figure,hold on,ah=gca; %# make figure, set hold state to on 
for i=1:5, 
    %# use plot with axis handle 
    %# so that it always plots into the right figure 
    plot(ah,x+i,y*i); 
end 

Esto funcionará

x=1:10;y=ones(size(x)); %# create some data 
figure,hold on,ah=gca; %# make figure, set hold state to on 
xlim([0,10]),ylim([0,6]) %# set the limits before you start plotting 
for i=1:5, 
    %# use plot with axis handle 
    %# so that it always plots into the right figure 
    plot(ah,x+i,y*i); 
end 
Cuestiones relacionadas