Real time plot slows down due to hold on command
Afficher commentaires plus anciens
Hey, I have been trying to make a real-time plot to visualize some data which works fine except the plot severely slows down after about 40 seconds and also keeps using more and more RAM.
data = zeros(200,1); %Preallocate memory
i = 0;
time = [0.0001:.0001:0.02]';
figure(1);
hold on;
while 1
data = sin(time)*250+250;
time = [max(time)+.0001:.0001:max(time)+0.02]'; %Increase time interval by 20 ms
plot(time,data); %Plot the newest 200 samples
axis([min(time)-3 max(time), 0 , 1000]); %Plot the last three seconds
grid on;
if ~mod(i,8)*i/8>0 %Draw plot every 8th iteration to speed up plot
drawnow;
end
if i >= 4096 %Clear every 4096th iteration to save memory
i = 0;
end
i = i + 1;
end
When disabling the hold on command, the plot doesn't slow down but i of course only get the newest 200 samples. Since I don't really need to inspect more than ten seconds of data, is there anyway I can get around using the hold on command? I saw someone talking about using handles to only keep some of the plots but I don't know how to use those.
Thanks
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!