Reputation: 491
I'm trying to plot lots of single lines with different length. Therefore, I use a rather simple code:
p = csvread('C:\path\file.csv',2,0,[2,0,1000000,3]);
h=waitbar(0,'Plotting...');
for r=1:size(p,1)
waitbar(r/size(p,1),h);
r0=r;
t0=p(r0,4);
while(r<=size(p,1) && p(r,4)==t0)
r=r+1;
end
plot(p(r0:r-1,2),p(r0:r-1,3));
hold on
end
close(h);
This code iterates through each line of my csv file and plots the lines from r0
to r-1
for which p(r,4)
stays constant. I am not interested in seeing every single line being plotted, so I want Matlab to plot everything in the background and show me the result afterwards. Since that plotting takes quite some time, I'd like to see my waitbar updating while plotting in the background.
But there's a problem: everytime the waitbar updates, the plot is drawn (similar to the drawnow
command). This takes A LOT of time compared to drawing in the background. How can I update my waitbar without drawing the plot?
Upvotes: 1
Views: 438
Reputation: 5821
You can use set(h,'Visible','off');
to hide the plot until you need to see it. This only offers about a 25% speed reduction based on some quick tests I ran, however.
For example:
h = figure(1); %// get figure handle
set(h,'Visible','off') %// hide plot window
hold on;
t = -10:0.1:10; %// create curves on the plot
plot(t,sin(t),'b');
plot(t,sin(t+2*pi/3),'r');
plot(t,sin(t-2*pi/3),'g');
set(h,'Visible','on'); %// draw plot
Upvotes: 1