Mostrar comentarios más antiguos
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.
Respuestas (3)
Naz
el 24 de Nov. de 2011
put
fprintf('%d\n',progBar);
inside the loop
Jan
el 24 de Nov. de 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 comentarios
NUR KHAIRUNNISA rahimi
el 24 de Nov. de 2011
Jan
el 24 de Nov. de 2011
If you copy and paste my program, you do not get this output. Therefore I cannot know, how your out is created.
NUR KHAIRUNNISA rahimi
el 24 de Nov. de 2011
Jan
el 24 de Nov. de 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
el 14 de Dic. de 2011
0 votos
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
Categorías
Más información sobre App Building en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!