File Exchange

image thumbnail

displayInline

version 1.0.0.0 (1.65 KB) by Damith Senaratne
Displays a string inline in the MATLAB Command Window, overwriting any text it previously displayed.

0 Downloads

Updated 12 Aug 2011

View License

Displays a string inline in the command window, overwriting any output the method previously displayed.

Useful to update any displayed string in-place, for example to indicate the the state of a simulation in progress.

-----------------------------------
e.g.
displayInline;
tic;
for k = 1:1e6
if mod(k,1000)==0
displayInline(sprintf('test: iteration %d, elapsed time: %g s', k, toc));
end
...
RepeatSomeTimeConsumingTask;
...
end
displayInline(sprintf('test: completed %d iterations (in %g s)', k, toc));
-----------------------------------

A persistent variable 'displayInlineCount' is used to keep track of the length of the previously displayed string, so that it can be erased the next time.

'displayInlineCount' is reset if no argument is passed in or 'str' is null.

Note: Any output on the command window made by other functions (e.g. display) between successive calls to displayInline would cause an incorrect portion of the output to be overwritten.

Cite As

Damith Senaratne (2020). displayInline (https://www.mathworks.com/matlabcentral/fileexchange/32510-displayinline), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (1)

Hi,

I use 'dispstat' function just for this purpose. It can update the previous output which is a missing function of default 'disp'. Very simple to use. It can be downloaded from here:

http://www.mathworks.com/matlabcentral/fileexchange/44673

***Sample usage:
dispstat('','init'); % One time only initialization
dispstat(sprintf('Begining the process...'),'keepthis','timestamp');
for i = 97:100
dispstat(sprintf('Progress %d%%',i),'timestamp');
%doing some heavy stuff here
end
dispstat('Finished.','keepprev');

***Output:
11:25:37 Begining the process...
11:25:37 Progress 100%
Finished.

All the best

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux