Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text progress bar in Matlab

I've got a Matlab function that takes some time to run, and I'd like to show the user that progress is being made. Just disping the progress every 5% or so would clutter the screen too much, as the previous text would not be erased.

How can this problem be solved? There's other important information in the command window, so clearing it is out of the question.

like image 712
Andreas Avatar asked Jun 15 '12 11:06

Andreas


2 Answers

Showing the progess in the Command Window is also possible (and maybe easier). I found a very simple, fast to implement solution on http://undocumentedmatlab.com/blog/command-window-text-manipulation/.

reverseStr = '';
for idx = 1 : someLargeNumber

   % Do some computation here...

   % Display the progress
   percentDone = 100 * idx / someLargeNumber;
   msg = sprintf('Percent done: %3.1f', percentDone); %Don't forget this semicolon
   fprintf([reverseStr, msg]);
   reverseStr = repmat(sprintf('\b'), 1, length(msg));
end

If you embedd this code the command line is showing (for example): "Percent done: 27.8" without entering a newline every iteration!

like image 103
Semjon Mössinger Avatar answered Sep 30 '22 14:09

Semjon Mössinger


You can use waitbar function for that. See MATLAB Documentation on waitbar.

like image 38
nrz Avatar answered Sep 30 '22 14:09

nrz