File Exchange

image thumbnail

setPrompt - Set the Command Window prompt

version 1.4 (11.9 KB) by

Sets the Command Window prompt to the specified string

11 Ratings



View License

setPrompt(newPrompt) sets the Command Window prompt to the specified NEWPROMPT.
NEWPROMPT can be one of the following:

- a static string: setPrompt('>> ')
=> this is the default prompt string ('>> ')

- an evaluable string: setPrompt('datestr(now)')
=> the new prompt will look like: '25-Jan-2010 01:00:51'
Note: the evaluable string is expected to return a string

- an evaluable function: setPrompt(@()(['[',datestr(now),'] ']))
=> the new prompt will look like: '[25-Jan-2010 01:00:51] '
Note: the evaluable function is expected to return a string

- the static string 'timestamp' will continuously update the last (current)
prompt with the current time: '[25-Jan-2010 01:00:51] '. This has
the effect of displaying desktop command execution times.
The 'timestamp' string can be used with other static text to
customize its appearance. For example: setPrompt('<timestamp!> ').
- an empty value or no input argument restores the default prompt

setPrompt('[-]') % Replaces '>> ' prompt with '[-]'
setPrompt('%') % => '% ' (space-padded)
setPrompt('sprintf(''<%f>'',now)') % => '<734163.056262>'
setPrompt('datestr(now)') % => '25-Jan-2010 01:00:51' (unchanging)
setPrompt('[''['',datestr(now),''] '']') % => '[25-Jan-2010 01:00:51] '
setPrompt(@()(['[',datestr(now),'] '])) % => '[25-Jan-2010 01:00:51] '
(note that these are the same: the first uses an evaluable string,
while the second uses an evaluable function)
setPrompt('timestamp') % => '[25-Jan-2010 01:00:51] ' (continuously-updated)
setPrompt('<timestamp> ') % => '<25-Jan-2010 01:00:51> ' (continuously-updated)
setPrompt('>> ') % restores the default prompt
setPrompt('') % restores the default prompt
setPrompt % restores the default prompt

This code heavily relies on undocumented and unsupported Matlab functionality. It works on Matlab 7+, but use at your own risk!

Technical explanation:
A technical explanation of the code in this utility can be found on

Bugs and suggestions:
Please send to Yair Altman (altmany at gmail dot com)

Comments and Ratings (17)


I put setPrompt in my startup.m. It was causing "maxrhs: too many arguments error". I traced it to the jTextArea assignment at about line 96. It was trying to operate before the commandwindow was created. So I modified to this block that keeps retrying:

cmdWin = jDesktop.getClient('Command Window');
jTextArea = cmdWin.getComponent(0).getViewport.getComponent(0);
jTextArea = [];
while isempty(jTextArea)
disp('setPrompt: try getting jTextArea again');
jTextArea = jDesktop.getMainFrame.getFocusOwner;

Yair Altman

Yair Altman (view profile)

@Qun HAN - I've updated the utility for R2014a & R2014b. Download the latest version.


Qun HAN (view profile)

In MATLAB R2014A, I got the following error.

Error using setPrompt (line 115)
The name 'CaretUpdateCallback' is not an accessible property for an instance of class 'com.mathworks.mde.cmdwin.XCmdWndView'


This is what I was looking for
Thx Yair

Hi Yair

Great submission! Two questions

1) I've put setPrompt into startup.m. However, it doesn't work from there. I'm sure setPrompt is executed (added a disp statement to verify). It works fine AFTER Matlab is started

2) Any idea how to change the caret color? I've added
set(jTextArea,'caretColor',[1 0 0]);
to your code, but it doesn't seem to work. Neither does your uiinspect work on the property 'caretColor'



Gary (view profile)


really useful function, only one request. Could you look into debugging while using setPromt? If you debug step by step, it prints new setPromt message appending last one and deleting few symbols from last prompt. It looks like that:
'[2012-09-13 11:36:[2012-09-13 11:36:[2012-09-13 11:36:[2012-09-13 11:36:13]'
I could do that myself but that would take time to understand this code :) thanks


Brian (view profile)

Kenneth Eaton

Kenneth Eaton (view profile)

Very nice! The only problem I had when trying to run it on R2010b was this warning message:

Warning: Possible deprecated use of set on a Java callback.
> In setPrompt at 115

Which I suppressed by doing the following:



Andy (view profile)

I have a student edition of ML R2010a on Windows 7. It comes with the default prompt 'EDU>>', which I wanted to change back to the familiar '>>'. setPrompt worked, but it leaves too much space (copied and pasted):

EDU>> setPrompt('>>');
>> see how much space there is?

I would have preferred:

EDU>> setPrompt('>>');
>> only one space before text

Still, great stuff. Thanks, Yair!

Thank you very much Yair, your new version works perfectly. Tested successfully on R2008b and R2007b. Work also perfectly on R14SP3 adding a “try, if ismac … end”.

John D'Errico

John D'Errico (view profile)

I would only add (as one of the people who reported a Mac problem) that I saw the problem in release R2007b, on an old mac with probably an old copy of Java. For the rest of you, rest assured that this appears to be a well written, well documented, professional piece of code.

Yair Altman

Yair Altman (view profile)

*** Mac users ***
Please note that I have received information that setPrompt causes problems on MacOS. It appears to work ok on non-Mac platforms though (inc. Windows)

Yair Altman

Yair Altman (view profile)

oops - temporary problem with the webpage (now fixed)...

I don't know the legal status of removing the EDU from the prompt. Since this is the first time anyone has been able to modify the prompt, I think the question has never before arisen.

Jan Simon

Jan Simon (view profile)

I cannot get the link to the blog on undocumentedmatlab to run (-> 404 error).
Is there a statement from TMW, if removing "EDU" from the prompt conclicts with the license conditions? See:
If it is legal, I love it.

I thought that it was impossible to modify this "core" feature. tested successfully under R2010a Prerelease. Great job Yair!

Ragaar Ashnod



Updated submission title (no code change)


Fixed for R2014a & R2014b


Fixed a few edge-cases (some reported by J.G. Dalissier) with '>> ' terminated prompts; fixed a few problems with continuous timestamps; enabled customizing continuous timestamp prompts; added Mac warning


Fixed a few edge cases (some inspired by J. Raymond); added continuously-updated timestamp option

MATLAB Release
MATLAB 7.6 (R2008a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video