Borrar filtros
Borrar filtros

Plotting fresh plot for every iteration and change x-direction

7 visualizaciones (últimos 30 días)
How do i plot a fresh new plot for each iteration without stacking plots? And how do i change the X-direction, so the "flow" seems to come from the opposite direction?
I'm plotting a window of 3 hours seismic data which changes for every iteration. The seismic data is changing every 8 seconds (ideally) as if it was a live feed. When i run the script it plots every iteration on top of each other. I've tried to put the figure command at the top of the whole for-loop, but it doesn't help.
i also want To make the data flow from right to left, and not left to right, i've tried to insert set(gca, 'XDir','reverse'), but it still "feeds" from the right.
for k = 1:length(AAA)/8*sampleRate
V=AAA(1+k*8*sampleRate:(3*L)+k*8*sampleRate);
v2=flipud(V);
%L1=length(v2);
d1 = length(BPPUdpluk);
s = 1;
output = zeros(round(L/s),d1);
tic
for i=1:length(v2)-d1
xj2=0;
yj2=0;
xy2=0;
val2=0;
for j=1:d1
xj2=xj2+BPPUdpluk(j)*BPPUdpluk(j);
yj2=yj2+v2(j+i-1)*v2(j+i-1);
xy2=xy2+BPPUdpluk(j)*v2(j+i-1);
end
% val=xy/(sqrt(xj).*sqrt(yj))
corr3(i)=xy2/(sqrt(xj2)*sqrt(yj2));
end
toc
corr4 = corr3';
corr4 = flipud(corr4);
Udslag(k)=length(corr4(corr4>=0.25));
figure(6)
red=zeros(1,length(corr4));
red(:)=0.25;
time2 = (0:3/(length(corr3)-1):3);
subplot(2,1,1)
plot(time2,corr4,'color',[0 0.4470 0.7410])
xlabel('Time[Hr] - 3Hr window')
ylabel('CC')
%hold on
plot(time2,red,'r')
set(gca, 'XDir','reverse')
%axis([0 3 -1 1]);
set(gca,'xtick',[])
grid
%hold off
if Udslag(k) <=1
hold on
subplot(2,1,2)
bar(Udslag(k))
set(gca,'Color','g')
hold off
else
if Udslag(k) == 2
hold on
subplot(2,1,2)
bar(Udslag(k))
set(gca,'Color','y')
hold off
else
hold on
subplot(2,1,2)
bar(Udslag(k))
set(gca,'Color','r')
hold off
end
end
end

Respuesta aceptada

dpb
dpb el 15 de Jun. de 2019
Editada: dpb el 15 de Jun. de 2019
Some basic "issues"...
  1. Your figure line is figure(6) which always reverts to the same figure you requested so it's not surprising it's always plotting on the same figure--you gave it no choice.
  2. Which iteration loop is the one? Place a figure statement first thing after the beginning of that loop to create a new figure. Then create the new axes to plot into and set the parameters for it such as the 'XDir' parameter.
  3. plot is high-level function that resets much of the behind the scenes preliminaries for plotting...hold on bypasses a bunch of that but once you set it, you immediately turn it back off, losing the effect every iteration. "Don't do that!" when you want to continue to add to an existing plot; that's what it's for.
More efficient by far for such "realtime" plotting is to update the 'X|YData' properties directly as discussed and illustrated in the documentation for graphics under the heading of Animation in the section on 2D graphics. Several alternatives are given with examples..

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by