标题
%图标题中显示变量
figure;
a=1;
title(['figure ' num2str(a)]);
![](https://img-blog.csdnimg.cn/20210408104353559.jpg)
一、作图细节与技巧
1. 点、线属性
点、线形状颜色选择
2. 画布范围
axis tight;%自动填充整个画布
3. 坐标轴显示方式
(转载自https://jingyan.baidu.com/article/14bd256e4e426cbb6d2612fd.html)
Matlab对矩阵画图时,有两种坐标轴的显示方式 axis ij 和axis xy
axis ij :矩阵轴模式,原点在左上角,i轴是竖直的,由顶至底标数,j轴是水平的,从左往右标数。如图所示。
Matlab默认的也是这种模式,因为它跟矩阵的行列相对应,从左往右,从上而下,第一个数在左上角。i,j的值也正好对应着矩阵的行和列。所以出图后不加 axis ij和axis xy 语句,结果默认为axis ij模式。
axis xy :笛卡尔轴模式,原点在左下角,y轴是竖直的,由底至顶标数,x轴是水平的,从左往右标数。如图所示。
该模式与笛卡尔坐标相对应。出图语句后加上 axis xy,图就会转换成笛卡尔轴模式。
要换成矩阵轴模式只要再运行axis ij即可。
3. 设置图片大小
set(gcf,'unit','centimeters','position',[3 5 14 6]);%所在显示屏的位置(起点坐标) 设置图片大小
%set(gca,'Position',[.2 .2 .7 .65]);%所画图形在figure中占的比例
figure;
plot((0:length(dpowerAdvancedNear)-1)*Ts,dpowerAdvancedNear);
xlabel('Time/ms');
ylabel('Amptitude');
set(gcf,'unit','centimeters','position',[3 5 14 6]);
grid on;axis tight;
4. 设置标题
title( '\it{滤波器输入信号} ' );%标题是斜体
二、做有marker标记的图
clc;
clear all;
close all;
load('errorRate3_1.mat')
load('errorRate3_2.mat')
load('errorRate3_3.mat')
semilogy(SNR_dB,errorRate3_1,'r*','LineStyle','-');
hold on
semilogy(SNR_dB,errorRate3_2,'g*','LineStyle',':');
semilogy(SNR_dB,errorRate3_3,'b*','LineStyle','--');
legend('传统匹配相关','差分相关','差分能量');
xlabel('SNR/dB');
ylabel('BER');
grid on
注意,要每一个属性对应每一个参数,这样才能够正常使用所有的plot的属性设置
plot(v,dopplerfactor,'Color','r','Marker','o','LineStyle',':','LineWidth',1.3);
xlabel('Speed(m/s)');
ylabel('dopplerfactor');
hold on;
plot(v,EstimateDop,'Color','#0072BD','Marker','^','LineStyle','--','LineWidth',1.3);
legend('多普勒因子理论值','多普勒因子估计值');
三、做三维曲面图
1)surf 三维曲面图
figure;
surf(tao,kesai,abs(R));;xlabel('时延');ylabel('频偏');
shading interp;%模糊图
grid on;
shading interp 通过在每个线条或面中对颜色图索引或真彩色值进行插值来改变该线条或面中的颜色。
![](https://img-blog.csdnimg.cn/20210426185806458.png)
上图用mesh作图的结果:
![](https://img-blog.csdnimg.cn/20210426190127752.png)
![](https://img-blog.csdnimg.cn/20210426190855885.png)
用了shading interp 没用shading interp
2)mesh 三维网格曲面图
figure;
mesh(freq/B,t/T,ambig);axis tight;
xlabel('归一化频率/B');ylabel('归一化时间/T');zlabel('模糊函数');
title('m序列三维模糊图');
![](https://img-blog.csdnimg.cn/20210426185637261.png)
matlab中mesh()和surf()函数的主要区别是:
mesh()用于绘制不是特别精细的三维曲面网格图。同一层面的线条用相同的颜色表示。
surf()用于绘制比较光滑的三维曲面网格图。各线条之间的补面用颜色填充。
推荐使用mesh,这样不用自己设置shading interp,其会自动填充颜色
四、做三维曲线图
1)将多个二维曲线图在三维图中显示出来
%plot3+hold on+循环一起用
%每一次都固定一个维度画,再循环
clear all
clc
close all
te = [39 43 46 48];%x轴
fe = [42 64 128];%y轴
da=[141.73 155.17 166.89 177.75 %属于y轴第一个,即fe(1)
190.36 212.18 230.74 248.6
101.24 106.97 112.09 116.88];
da1=da+100;
for i=1:length(fe)
plot3(te,fe(i)*ones(size(te)),da(i,:),'r.-');
hold on
plot3(te,fe(i)*ones(size(te)),da1(i,:),'b.-');
end
grid on
[caz,cel] = view
%view(-37.5,30)
%view(-90,30)
五、做等高线图
figure;
contour(freq/B,t/T,ambig);grid on;%'ShowText','on'
xlabel('归一化频率/B');ylabel('归一化时间/T');
title('m序列模糊度图');
![](https://img-blog.csdnimg.cn/20210426185538269.png)
做伪彩图
1)imagesc()
figure;
imagesc(tao,kesai,abs(R));
shading interp;
axis xy;%第一个点是左下角的点
xlabel('时延/ms');ylabel('频偏');
colormap(jet);
xlim([-0.015 0.015])
colorbar %显示色棒
2) pcolor
这两种暂时没查到明显的区别
六、做信道冲激响应图
h=zeros(1,20-3*fs+1);
h(1)=1;h(5e-3*fs+1)=0.7;h(10e-3*fs+1)=-0.4;h(15e-3*fs+1)=0.5;h(20e-3*fs+1)=0.3;%
figure;stem((0:length(h)-1)*Ts*1e3,h,'o');
xlim([0 (length(h)-1)*Ts*1e3]);
xlabel('Time/ms');
ylabel('Amptitude');
grid on