Efficient online plot?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I wonder why Matlab memory usage increases with this simple code updating the plot recursively.
% subplot initialization
figure,subplot 311,ha{1} = plot(rand(100,1));
subplot 312,ha{2} = plot(rand(100,1));
subplot 313,ha{3} = plot(rand(100,1));
% recursive calc and update plot
for i = 1 : N % some long recursive calculation
Y = rand(100,3); % some calculation or simply rand(100,3) applied gives the same problem; % Y was pre-allocated and is kept of the same size; where 3 corresponds to 3 lines
plot_update(ha,Y)
memory % measuring the memory consumed by Matlab
end
% --- func for updating plot
function plot_update(ha,Y)
for i = 1 : length(ha)
set(ha(i),'LineJoin','round','YData', Y(:,i)); %hold on; % 'auto y';
end
So, the Y matrix is of constant size and used to update YData of the plot at every step of the calculation. Looking at the Matlab's memory usage, it slowely but steadily increases with time and I cannot figure it out. Thank you on any comments how to improve the code.
1 Commento
Jan
il 28 Dic 2018
Just a hint, but not the problem: You define ha as a cell. It works to provide the handle as a scalar cell, but it might be more clear to use an array of handles:
ha(1) = plot(rand(100,1)); % Instead of curly braces {1}
Risposte (1)
Jan
il 28 Dic 2018
Modificato: Jan
il 28 Dic 2018
What is the problem you want to solve? Matlab creates new data in each iteration by:
Y = rand(100,3);
The former values are not needed anymore, but a garbage collection would need some time. Therefore it is possible that Matlab waits until collecting free memory is required and until then is seems like the used memory is growing, but it is only the part, which has not been declared as free. So I assume, that there is no problem at all.
By the way, the subplot 131 style is outdated since Matlab 5.3 - for 20 years now. It is time to use the modern style subplot(1,3,1).
Vedere anche
Categorie
Scopri di più su Graphics Objects in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!