Progress bar
    9 views (last 30 days)
  
       Show older comments
    
I have a list of words(maybe consist of 250000) where I would like to remove the plural form of all the word ending with s. While I am doing that, I have to dispplay a progress bar on the screen.
So this is what I have so far. However,
 for iword=1:length(wordbank)
if ~isempty(wordbank{iword})&& strcmp(wordbank{iword}(end), 's') no_plurals=no_plurals+1; wordbank2{iword} = wordbank{iword}(1:(end-1));
       progBar=(iword/(length(wordbank)))*100;
    end
fprintf('%d\n',progBar);
however, my program only show the end result of the process, which is 100% and not incrementing the value while processing from 1% to 100%. Can you help me fix this? Thank you.
0 Comments
Answers (3)
  Jan
      
      
 on 24 Nov 2011
        Cleaned a little bit:
fprintf('    ');
fmt = [char([8,8,8,8]), '%3d%%'];
singular = 0;  % Nicer than no_plural
nword = length(wordbank);
wordbank2 = cell(1, nword);
update = 1;
for iword = 1:nword
  word = wordbank{iword};
  if ~isempty(word) && word(end) == 's'
    singular = singular + 1;
    wordbank2{iword} = word(1:(end-1));
    progBar = 100 * iword / nword;
    if progBar > update
      fprintf(fmt, update);
      drawnow;
      update = round(progBar) + 1;
    end
  end
end
EDITED: overwrite the percentage string
index     = strncmpr(wordbank, 's', 1);
wordbank2 = wordbank(~index);
The timings (Matlab 2009a, Win7, 250'000 words with 6 ot 7 characters):
 Loop with progress display:    2.0 sec
 Loop without progress display: 0.8 sec
 strncmpr:                      0.02 sec
Are you sure you want to waste the most time for updating the progress display?
4 Comments
  Jan
      
      
 on 24 Nov 2011
				I've inserted some code to overwrite the percentage string inplace.
I do not know, why your program is not doing, what you expect. But I do neither know the program nor what you expect. Perhaps you want to explain both? But as far as I can see, the original question is answered.
  Sameer Kumthekar
 on 14 Dec 2011
        Hi , I think you can use waitbar something like this..
h = waitbar(0,'Removing the plural form of all the words...Please wait..!');
steps = 100; for step = 1:steps  code here h = waitbar(step/steps,sprintf('%d%%',step)); end close(h);
Please check once! Sameer K
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


