整理归纳常用matlab操作

概述

本文用于整理归纳常用到的一些matlab操作,供时常复习。

正文

%创建矩阵(1、手动输入 2、函数创建)
a0 = [1 2 3;4 5 6;7 8 9];%手动创建矩阵
b0 = ones(3, 3);%创建3x3的全1矩阵
c0 = zeros(3, 3);%创建3x3的全0矩阵 
d0 = rand(3, 3);%创建3x3的随机矩阵,元素范围(0~1之间)

%矩阵运算
a = [1 2 3;4 5 6;7 8 9];
a1 = a';%求矩阵a的转置矩阵
b1 = inv(a);%求矩阵的逆矩阵
c1 = a*inv(a);%求单位矩阵
d1 = a.*a;%a矩阵元素各自平方

%画图
%{
x = 0:pi/100:2*pi;
y1 = cos(x);
y2 = sin(x);
%plot(x,y);%画一维图
plot(x,y1,'r');%用红色线画图
hold on;%保持上次画图,接着画
%plot(x,y2,'b:');
plot(x,y2,'b-.x');%设置蓝色线段式样
legend('cos','sin');%设置图例
xlim([0 10]);%设置横坐标范围
ylim([-1 1]);%设置纵左边范围
xlabel('x');%设置横左边标签
ylabel('cos(x)');%设置纵坐标标签
title('Plot of the sine function');%设置图形标题
%}
%{
x = 0:pi/100:2*pi;
y1 = cos(x);
y2 = sin(x);
subplot(2,2,1);%多子图绘制
plot(x,y1);
subplot(2,2,2);
plot(x,y2);
%}

%画三维图
%{
t = 0:pi/10:2*pi;
[X,Y,Z]=cylinder(4*cos(t));
subplot(2,2,1);
mesh(X);
title('X');
subplot(2,2,2);
mesh(Y);
title('Y');
subplot(2,2,3);
mesh(Z);
title('Z');
subplot(2,2,4);
mesh(X,Y,Z);
title('X,Y,Z');
%}

%{
%Axis设置
%可见性设置
axis on;%设置可见
axis off;%设置不可见
%网格线设置
grid on;%设置可见
grid off;%设置不可见
%长宽比设置
axis square;%设置X,Y轴等长
axis equal;%设置X,Y相同递增
axis auto normal;%设置自动模式
%设置轴界限
axis([xmin xmax ymin ymax]);
axis([xmin xmax ymin ymax zmin zmax]);
axis auto;
%}

%卷积
a2 = [1 2 3];
b2 = [1 1];
c2 = [1 2 3;4 5 6];
d2 = [1 1 1;2 2 2];
conv(a2,b2);%一维卷积
conv2(c2,d2);%二维卷积

%FFT
Fs = 1024; %采样频率
N = 1024; %采样点数
n = 0:N-1;
t = n/Fs; %时间序列
f = n*Fs/N; %频率

x = sin(2*pi*50*t) + cos(2*pi*200*t);
y = fft(x, N);
subplot(2,1,1);
plot(x(1:250));
subplot(2,1,2);
P1 = abs(y);
plot(f,P1);%显示双边频率
%plot(Fs*(0:(N/2))/N, P1(1:N/2+1));%显示单边频率

总结

持续更新…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值