散装绘图技巧
1. colorbar - TITLE显示
h = colorbar;
set(get(h,'Title'),'string','cm');
2. 字符串换行输出
字符串换行输出:
Cell格式
—— 用大括号,分号分割 { ‘a’ ; ’b’ }。
3. 将信号数据矩阵转换为声音【sound】
个人使用情况:
- 通常放在需要跑较长时间的代码最后,用来
提醒代码运行结束
load chirp.mat; % MATLAB 自带很多示例文件 可以上网找找
sound(y);
4. 绘图填色透明度调节【facealpha】
命令:
'facealpha'
,函数后面的参数设置。
x = [0 2 2 0];
y = [0 0 1 1];
c = [1; 0.5; 0; 0.75];
xp = 0:pi/10:pi;
yp = sin(xp);
%% ========================================================================
figure
subplot(1,3,1)
plot(xp,yp,'-','LineWidth',1.5);hold on
fill(x,y,c);
text(1,0.2,'未加透明度')
%------------------------
subplot(1,3,2)
plot(xp,yp,'-','LineWidth',1.5);hold on
fill(x,y,c,'facealpha',0.8); % ****************** %
text(1,0.2,'透明度:0.8')
5. 换行(text,legend等均可用)
方法1:sprintf(‘\n’)
方法2:newline(方法1会给警示,并给推荐用方法2)
6. 给(*.m)文件删除空格行和注释行
function ToremoveCommentInMCode(Mfile)
code = fileread(Mfile);
PureCode = mtree(code).tree2str();
fileID = fopen(['a_',Mfile],'w');
fprintf(fileID,PureCode);
fprintf 会出现一个错误:若m文件代码行中存在
'%s'
之类的含"%
"字符的语句,则输出时会出错。
解决办法:
将原文件中“%”全部替换成“%%”,因为fprintf中“%%”的输出才代表“%”