matlab在终端显示有颜色的字(cprintf函数的用法)
来源:互联网 发布:软件编程职业培训 编辑:程序博客网 时间:2024/04/29 16:53
我们知道在matlab中显示文字用display,但它显示出来的颜色默认是黑色字体,我们要相在终端显示有颜色的字体怎么办呢?
有以下两种方法供参考:
1.用fprintf函数如下:
>>fprintf(2,'红颜色\n')
红颜色
不过它有个缺点是只能显示这种error的红颜色
2.用cprintf函数,这是国外的一个叫Yair M. Altman的人写的程序,它的博客地址为:
这个函数的下载地址为:(下载后将放入当前程序运行目录下就可以调用了)
点击下载(download)
它的用法我来简单翻译一下:
语法: count = cprintf(style,format,...)
描述: CPRINTF 用指定格式(style)来处理指定的文档
可用的格式名为
'Text' -- 默认:黑色black
'Keywords' -- 默认:蓝色 blue
'Comments' -- 默认:绿色green
'Strings' -- 默认:紫色 purple
'UnterminatedStrings' -- 默认:暗红 dark red
'SystemCommands' -- 默认:橘色 orange
'Errors' -- 默认:淡红 lightred
'Hyperlinks' -- 默认:带下划线的蓝色underlined blue
其他颜色如下
'Black','Cyan','Magenta','Blue','Green','Red','Yellow','White'
注意: 以'-'开始的是下划线,例如:
'-Blue' 是蓝色的下划线,与'Hyperlinks'相似
STYLE 也接受通用的RGB向量做为参数,在它前面加负号,表示下划线,例如:
-[0,1,1]表示带下划线的蓝绿色cyan
STYLE 不区分大小写 (case-insensitive),接受唯一的部分字符串
一些实用例子:
附原文帮助文件:
或参照http://www.mathworks.com/matlabcentral/fileexchange/24093
% CPRINTF displays styledformatted text in the Command Window
%
% Syntax:
% count = cprintf(style,format,...)
%
% Description:
% CPRINTF processes the specified text usingthe exact same FORMAT
% arguments accepted by the built-in SPRINTFand FPRINTF functions.
%
% CPRINTF then displays the text in theCommand Window using the
% specified STYLE argument. The acceptedstyles are those used for
% Matlab's syntax highlighting (see: File /Preferences / Colors /
% M-file Syntax Highlighting Colors), andalso user-defined colors.
%
% The possible pre-defined STYLE names are:
%
% 'Text' - default: black
% 'Keywords' - default: blue
% 'Comments' - default: green
% 'Strings' - default: purple
% 'UnterminatedStrings' - default: dark red
% 'SystemCommands' - default: orange
% 'Errors' - default: light red
% 'Hyperlinks' - default: underlined blue
%
% 'Black','Cyan','Magenta','Blue','Green','Red','Yellow','White'
%
% Note: styles beginning with '-' will beunderlined. For example:
% '-Blue' is underlined blue, like'Hyperlinks';
% '-Comments' is underlined green etc.
%
% STYLE also accepts a regular Matlab RGBvector, that can be negated
% for underlining. For example: -[0,1,1]means underlined cyan.
%
% STYLE is case-insensitive and acceptsunique partial strings just
% like handle property names.
%
% CPRINTF by itself, without any inputparameters, displays a demo
%
% Example:
% cprintf; % displays the demo
% cprintf('text', 'regular black text');
% cprintf('hyper', 'followed %s','by');
% cprintf('k', '%d colored', 4);
% cprintf('-comment','& underlined');
% cprintf('err', 'elements\n');
% cprintf('cyan', 'cyan');
% cprintf('-green', 'underlined green');
% cprintf(-[1,0,1], 'underlined magenta');
% cprintf([1,0.5,0],'and multi-\nlineorange\n');
% cprintf('string'); % same as fprintf('string') andcprintf('text','string')
- matlab在终端显示有颜色的字(cprintf函数的用法)
- cprintf()、textcolor()函数的使用
- Linux下C 更改字符在终端的显示颜色
- bootloader在终端有显示,kernel没有的原因
- matlab 图像颜色的显示
- 终端输出有颜色的文本日志
- 终端打印有颜色的字体
- linux终端下的颜色显示
- ubuntu终端显示的颜色配置
- cprintf 与 printf 的区别:
- cprintf与printf的区别
- matlab中text 函数在显示字符串时的使用方法
- matlab中text 函数在显示字符串时的使用方法
- Iterm 2 配色, 有颜色的MAC终端
- 终端的字符颜色
- Matlab 的fspecial函数用法
- Matlab函数accumarray的用法
- Matlab的imfilter函数用法
- 多线程之四 一个经典的多线程同步问题
- 超级隐蔽的小说阅读器
- Java医药桌面系统w
- 孙鑫-MFC笔记十一--动态链接库
- fstream详解
- matlab在终端显示有颜色的字(cprintf函数的用法)
- Android source build/envsetup.sh学习笔记
- 21个电脑小技巧
- Doubango 定时器管理用法
- Web页面制作基础(一)
- 多线程之五 经典线程同步 关键段CS
- Linux/hp unix/AIX日常巡检脚本
- AccessViolationException 图
- MD5简单的应用