📄 ch2example24commandslist.txt
字号:
>> clear;
>> t=[0; 1; 2]; % 时间序列
>> f1=[1; 2; 3]; % 信号1
>> f2=[4; 2; 5]; % 信号2
>> simin=[t,f1,f2] % 组成输入信号变量并显示其结构
simin =
0 1 4 % 第1列为时间序列,2,3列分别为两信号序列
1 2 2
2 3 5
>> mysimopts = simset('Solver','ode5'); % 设置仿真求解器为ode5的
>> mysimopts = simset(mysimopts,'FixedStep',0.5); % 设置仿真步进为固定的0.5秒
>> timespan=[0, 4]; % 仿真时间段参数
>> whos % 查看当前工作空间的变量
Name Size Bytes Class
f1 3x1 24 double array % 信号1
f2 3x1 24 double array % 信号2
mysimopts 1x1 2620 struct array % 仿真参数结构变量
simin 3x3 72 double array % 输入信号变量
t 3x1 24 double array % 时间序列
timespan 1x2 16 double array % 仿真时间段参数
Grand total is 46 elements using 2780 bytes
>> sim('ch2example24',timespan,mysimopts); % 设置仿真参数,仿真时间段并执行仿真
>> whos % 仿真完毕后查看当前工作空间的变量
Name Size Bytes Class % 注意新增了两个变量
f1 3x1 24 double array
f2 3x1 24 double array
mysimopts 1x1 2620 struct array
simin 3x3 72 double array
simout 9x3 216 double array % 仿真输出信号变量
t 3x1 24 double array
timespan 1x2 16 double array
tout 9x1 72 double array % 仿真输出时间序列
Grand total is 82 elements using 3068 bytes
>> simout % 查看仿真输出数据
simout =
4.0000 1.0000 0 % 第一列是两个输入信号相乘的结果。由于
4.5000 1.0000 0.5000 % “From Workspace”模块设置为内插值的,
4.0000 1.0000 1.0000 % 所以在0.5,1.5,...秒时间上的输出是输入
8.7500 1.0000 1.5000 % 信号插值结果的乘积。而我们又设置了信号
15.0000 1.0000 2.0000 % 终止后“Setting to zero”,所以在2秒之后
0 1.0000 2.5000 % 的输入值均为零。其乘积也就均为零了。
0 1.0000 3.0000 % 输出矩阵的第二列是直流信号,即Constant模块
0 1.0000 3.5000 % 输出的1输出矩阵的第3列是仿真时钟Clock的
0 1.0000 4.0000 % 输出,也即仿真时间序列。
>> tout % 显然,tout与simout中的Clock的输出相同。
tout =
0
0.5000
1.0000
1.5000
2.0000
2.5000
3.0000
3.5000
4.0000
>> % 实验完毕
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -