|
arun <aragorn168b@gmail.com> wrote in message <df998865-b878-42d4-ba80-cd8fcbfaa5bd@o13g2000vbl.googlegroups.com>...
> On Sep 22, 4:14?pm, "Sebastiaan"
> <s.breedv...@erasmusmc.REMOVE.BOO.BOO.nl> wrote:
> > GUI updates and wais. Use
> > profile on
> > <run your code>
> > profreport
> >
> > to check how much time is spend in the functions.
> >
> > I prefer to display progress in the command window, like:
> >
> > Total = 240000;
> > fprintf('Please wait: %3d%%', 0);
> > for j=1:Total
> > ? ? fprintf(sprintf('%s%%3d%%%%', repmat('\b', 1, 4)), round(j/Total*100));
> > end
> > fprintf('. Done!\n')
> >
> > Or:
> > places = ceil(log10(Total+1));
> > totalplaces = places*2 + 1;
> > fprintf(sprintf('Please wait: %%%dd/%d', places, Total), 0);
> > for j=1:Total
> > ? ? fprintf(sprintf('%s%%%dd/%d', repmat('\b', 1, totalplaces), places, Total), j); ? ?
> > end
> > fprintf('. Done!\n')
> >
> > It basically uses the backspace character to erase the previous characters and overwrites them. The only disadventage is that the logfile (-logfile at startup) gets bloated by \b's, so you need a program or editor that interpretates the \b correctly.
> >
> > Sebastiaan
> >
> > arun <aragorn1...@gmail.com> wrote in message <ec5f109b-3d69-4083-81cd-c34e0087b...@l35g2000vba.googlegroups.com>...
> > > I really don't understand this.
> >
> > > My simulation (with a for-loop over 240000 times) takes about 21
> > > seconds to complete.
> > > I use disp(i); inside to see how much is remaining.
> >
> > > Instead, I tried to use
> > > h = waitbar(0, 'please wait...');
> >
> > > for i=1:iy,
> > > ? ?waitbar(i/iy, h);
> > > ? ?....
> > > end
> >
> > > And it took 576 seconds!!! What is wrong here?
> >
> > > best, arun.
>
> Hi Sebastiaan,
>
> Thank you for your reply. But this itself takes about 1/2 a minute to
> execute. My code runs for around 20 seconds without any display and
> about 32 seconds with disp(i);
> By using this it goes to about a minute and a half to 2 minutes. which
> is not acceptable as i have to run this again a 1000 times.
>
> Total = 240000;
> fprintf('Please wait: %3d%%', 0);
> for j=1:Total
> fprintf(sprintf('%s%%3d%%%%', repmat('\b', 1, 4)), round(j/
> Total*100));
> end
> fprintf('. Done!\n')
>
> However, it looks clean. I will stick with disp(i); for now i guess.I
> don't know why it takes so much time to know where it is than the
> actual calculations!
>
> best, arun.
When program in Matlab, think OVERHEAD, OVERHEAD, OVERHEAD, OVERHEAD, ...
The total waitbar length is about 300 pixels. Do you need to call it so often (about 1000 times before it can move 1 pixel)?
Make it coarse, try to update it no more than 100 times.
Bruno
|