What are other types of messages than warnings and errors?

20 次查看(过去 30 天)
So far I have been using just two methods for messaging to inform the user during the run of a script: The warning() function:
and the error() function:
They both give simple yet noticeable coloured messages. But at the same time they also contain prefixes Warning and Error using ... (line ...).
I was therefore wondering if there are other methods/functions for messaging that can be quickly sent to the screen during a script? Maybe a neutral message in, say, blue colour that is neither a warning nor an error but simply a note() or message() or FYI() or similar?
Alternatively, are the warning() and error() messages generally editable so I can remove/alter the prefixes?

回答(1 个)

Stephen23
Stephen23 2018-2-9
编辑:Stephen23 2018-2-9
There is no documented way to get arbitrarily colored text in the command window. The only documented features with colored text are error (red), warning (orange), and by adding a hyperlink (blue):
Actually hyperlinks are more versatile than most users realize, and are sadly underutilized:
To get text in any arbitrary color you could download and use Yair Altman's excellent FEX submission cprintf, which relies on some undocumented functionality and features of MATLAB:
Thus you can simply create your own message using whatever color you want, and even define it in a function called note, message, or whatever. Note that cprintf is not supported by the MATLAB documentation and could break, so use it at your own risk.
Yair Altman's blog explaining the development of cprintf is definitely worth reading:

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by