Pregunta

cómo es exactamente lo que obtiene la escala fija de ejes en parcela de Matlab al trazar dentro de un bucle? Mi objetivo es ver cómo los datos está evolucionando dentro del bucle. He intentado utilizar axis manual y axis(...) sin suerte. ¿Alguna sugerencia?

Yo sé hold on hace el truco, pero no quieren ver los datos antiguos.

¿Fue útil?

Solución

Si desea ver los nuevos datos representados sustituyen a los antiguos datos representados, pero mantienen los mismos límites de ejes, puede actualizar los valores X e Y de los datos representados mediante el comando SET dentro de su bucle. 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, se verá un salto asterisco en torno a los ejes de un par de segundos, pero los límites ejes permanecerá fijo. Usted no tiene que utilizar el comando href="http://www.mathworks.com/help/techdoc/ref/hold.html" rel="noreferrer">

Otros consejos

Se tiene que establecer los límites de los ejes; lo ideal es hacerlo antes de comenzar el bucle.

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

Este trabajo

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
scroll top