Eugenio
Eugenio

Reputation: 3445

Show progress of a Matlab instruction execution

Is there any way to show the execution progress (even a rough estimation) of a Matlab instruction?

For example let's say I am computing distances using pdist:

D = pdist(my_matrix,'cosine');

and this computation takes hours, does Matlab provide any way to show periodically the execution progress?

Upvotes: 0

Views: 122

Answers (1)

craigim
craigim

Reputation: 3914

Not intrinsically. You can of course do after-the-fact checking with the profiler or tic/toc.

If this is something you will be doing a lot for a single function, you could consider modifying the function and saving it in your path with a new name (I have a directory called "Modified Builtin" for just this purpose). In the case of pdist.m, you might save pdist_updates.m. Looking a the function, the actual distances are calculated starting around line 250 with a series of nested loops. Add in a line like:

disp(sprintf('Processing pair %d of %d',i,n-1));

at line 265. If you really wanted to get fancy, you could use tic and toc to time each loop and provide an estimate of how long the entire calculation would take so you would know how long you had to run to the coffee machine.

Of course this will cause problems if you end up cancelling your Statistics Toolbox license or if Mathworks upgrades the toolbox and changes the functionality, so use this approach sparingly.

Upvotes: 1

Related Questions