Ai
1 Star 0 Fork 0

Vincent/MATLAB_Study

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
example.m 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
VINCENT 提交于 2022-10-23 19:25 +08:00 . MATLAB学习(修改版1)
%% IV.MATLAB矩阵操作
%%
% 1.矩阵定义与构造
A=[1 2 3 4 5 8 5 4]
B=1:2:9
C=repmat(B,3,2)
D=ones(2,4)
%%
% 2.矩阵的四则运算
A = [1 2 3 4;5 6 7 8]
B = [1 1 2 2;3 3 4 4]
C = A + B
D = A - B
E = A .* B'
F = A .* B
G = A / B
H = A ./ B
%%
% 3.矩阵的下标
A = magic(5)
B = A(2,3)
C = A(3,:)
D = A(:,4)
[m,n] = find(A>10)
%% VII.MATLAB基本绘图操作
%%
%1.二维平面绘图
x = 0:0.01:2*pi;
y = sin(x);
figure %建立一个幕布
plot(x,y)
title('y = sin(x)')
xlabel('x')
ylabel('sin(x)')
xlim([0 2*pi])
%%
%多重衰减率曲线图
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.05*x).*sin(10*x);
figure
[AX,H1,H2]= plotyy(x,y1,x,y2,'plot');
set(get(AX(1),'Ylabel'),'String','Slow Decay')
set(get(AX(2),'Ylabel'),'String','Fast Decay')
xlabel('Time (\musec)')
title('Mutiple Decay Rates')
set(H1,'LineStyle','--')
set(H2,'LineStyle',':')
%%
% 1.三维立体绘图
t = 0:pi/50:10*pi;
plot3(sin(t),cos(t),t)
xlabel('sin(t)')
ylabel('cos(t)')
zlabel('t')
grid on
axis square
% 2.双峰函数
[x,y,z] = peaks(60);
mesh(x,y,z)
grid
%%
%图形窗口分割
x = linspace(0.2*pi,60);
subplot(2,2,1)%二行二列第一个
plot(x,sin(x)-1);
title('sin(x)-1');axis([0,2*pi,-2,0])
subplot(2,1,2)
plot(x,cos(x)+1);
title('cos(x)+1');axis([0,2*pi,0,2])
subplot(4,4,3)
plot(x,tan(x));
title('tan(x)+1');axis([0,2*pi,-40,40])
subplot(4,4,8)
plot(x,cot(x));
title('cot(x)');axis([0,2*pi,-35,35])
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
其他
1
https://gitee.com/Vincentstudy/MATLAB_Study.git
git@gitee.com:Vincentstudy/MATLAB_Study.git
Vincentstudy
MATLAB_Study
MATLAB_Study
master

搜索帮助