I would like to plot some data like an oscilloscope, going from the right to the left part of the screen.
Afficher commentaires plus anciens
I am currently plotting the spectrogram of a signal, and I would like to display it, on a 2D manner (only time vs frequency is in my interest - fact which i have managed to do for a single plot), and refresh it on a regular basis, adding incremental plots to an image. The plotting of a data is normal: from left to right. I want the actual incremental parts to be added to the plot figure, in such a manner like an oscilloscope: add the latest calculated spectrogram in the right most part of the plot figure, and when the current dimension of the plot figure is filled, the left most will not be displayed anymore after the next increment. Thank you! Andrei
Réponses (1)
Teja Muppirala
le 2 Mai 2011
You first create a graphics object, then update it's properties little by little, for example like this:
y = randn(1,1000);
h = plot(y(1:200));
ylim([-5 5]);
n = 2;
while n+199 <= numel(y)
newy = y(n+(1:199));
set(h,'ydata',newy);
drawnow;
n = n+1;
end
3 commentaires
Teja Muppirala
le 2 Mai 2011
Here I created all the data at the beginning, and then plotted it in a loop. But if your data points are not all available at the beginning, and they are coming in one-by-one, then you can do something like this inside the loop:
oldy = get(h,'ydata');
newy = [oldy(2:end) newdatapoint];
set(h,'ydata',newy)
Andrei
le 4 Mai 2011
Teja Muppirala
le 4 Mai 2011
Did you remember to put in the DRAWNOW command?
t = 1:10000;
% Make some arbitary signal...
y = sin(t.^interpft(rand(1,20),10000));
Y = abs(spectrogram(y,20));
h = imagesc(zeros(size(Y,1),50));
set(gca,'clim',[0 max(Y(:))])
for n = 1:size(Y,2)
data = get(h,'cdata');
data = [data(:,2:end) Y(:,n)];
set(h,'cdata',data)
drawnow;
end
Catégories
En savoir plus sur Data Import and Analysis dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!