What are other types of messages than warnings and errors?
16 次查看(过去 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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/170107/image.png)
and the error() function:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/170108/image.png)
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?
0 个评论
回答(1 个)
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:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!