Progress bar

8 visualizzazioni (ultimi 30 giorni)
NUR KHAIRUNNISA rahimi il 24 Nov 2011
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));
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.

Risposte (3)

Naz il 24 Nov 2011
inside the loop

Jan il 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);
update = round(progBar) + 1;
EDITED: overwrite the percentage string
But there are much faster methods. E.g. see FEX: strncmpr.
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 Commenti
Jan il 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.

Accedi per commentare.

Sameer Kumthekar
Sameer Kumthekar il 14 Dic 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


Scopri di più su Programming Utilities in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by