Following my post on Changing Matlab’s Command Window colors, I received an email asking whether it was possible to temporarily set the Command-Window (CW)’s text color, so that subsequent disp or fprintf commands will be displayed in some specific text color.
The short and simple answer is no: You can change the text color as described in that post, but once you modify it, the entire CW text will be modified accordingly.
Unfortunately, CW (like Swing’s standard JTextArea of which CW is an instance) does not automatically support HTML formatting as most other uicontrols. In fact, CW’s default Document object, which holds all the text-area’s text and font style information, is an extension of Swing’s javax.swing.text.PlainDocument, which does not allow any text style formatting. And the CW object itself is a simple JTextArea, which does not enable using a styled Document object. Perhaps in a future version MathWorks would be willing to use the almost identical (syntactically-wise) JTextPane, which does enable styled text runs.
To a very limited degree, you can use the fact that hyperlinks and error messages have separate styles than standard text (respectively, blue underlined and red). So, you can output text in these styles as follows:
% Use hyperlink style: >> disp('<a href="">my text</a>') my text % Use STDERR (fid=2) style: >> fprintf(2,'my text\n') my text
Note: you could possibly get a handle to the JTextArea (see the previous post) and then set its UI property to your tailor-made Java UI class. In this class you can set text segment properties based on whichever properties you wish. This is apparently how Matlab overcame JTextPane’s limitations: they implemented a custom com.mathworks.mde.cmdwin.CmdWinSyntaxUI class that extends javax.swing.plaf.basic.BasicTextAreaUI. But implementing such a custom UI class while retaining Matlab’s syntax-highlighting functionality is most probably very difficult and not worth the effort. So we’ll just wait for some supported method in a future Matlab release.
Addendum (May 13, 2009): I have found a way to enable display of text in any color, as well as underline, in the Command Window. See my post on cprintf for details.
Clever use of the tools at hand! We would definitely like to allow users to change the color of their text in the Command Window (this is a frequent request). We’re thinking about more robust highlighting mechanisms now.
Depending on your needs, publishing could also serve as an intermediate solution, as you could embed HTML into your output, which would then be rendered by a web browser.
[…] In earlier posts I showed how to modify the Command Window (CW) text and background color, and a very limited method of displaying red (error) and blue (hyperlinked) CW messages. Since then, I was obsessed with finding a better way to CW display text in any color. After lots […]
can be used add a matlab command to run when the text is clicked
href=”matlab:disp(‘Command replaces disp(….) etc’)”
I am Beginner to MATLAB. By using the command NET.addAssembly i am loading .NET Assembly. Instantiating the object of Assembly’s class i am invoking the methods of the class.
Passing the parameter such as double, char to method of assembly class its working fine.
But when i am trying to pass cell array to method of instantiated class its showing the error parameter mismatch.
i have done following procedure
As reference from MATHWORKS, using this object passing the Cell array to method which has parameter as System.Object.
So please help me for how to pass cell array to .NET method.