-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathrun_all_tutorials.m
More file actions
120 lines (110 loc) · 3.24 KB
/
Copy pathrun_all_tutorials.m
File metadata and controls
120 lines (110 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
function run_all_tutorials()
%RUN_ALL_TUTORIALS 一键依次运行全部 43 个教程
%
% 每课运行完毕后暂停,方便查看模型和截图;
% 所有 Figure 会同时自动保存为 PNG 到 docs/images/,
% 可直接用于 README 配图。
%
% 用法:
% >> run_all_tutorials
tutorials = { ...
% Phase 1 — 基础
't01_signal_basics'
't02_math_blocks'
't03_first_order_sys'
't04_second_order_sys'
't05_pid_control'
't06_sources_and_sinks'
't07_subsystem'
't08_masking'
% Phase 2 — 经典控制设计
't16_freq_domain'
't17_lead_lag'
't22_root_locus'
% Phase 3 — 现代控制理论
't09_state_space'
't10_state_feedback'
't11_observer'
't12_kalman_filter'
% Phase 4 — 高级控制专题
't18_system_id'
't19_robust_control'
't20_mpc'
't21_sliding_mode'
't23_mrac'
't24_fuzzy_control'
% Phase 5 — 机电系统与部署
't13_dc_motor'
't14_foc_pmsm'
't25_simscape'
't15_code_generation'
% Phase 6 — 综合应用案例
't26_robot_kinematics'
't27_msd_modeling'
't28_dsp_basics'
't29_msd_control'
't30_active_suspension'
% Phase 7 — 非线性滤波 (新增)
't31_ekf_basics'
't32_ekf_pendulum'
't33_ukf_basics'
't34_ekf_vs_ukf'
't35_imu_fusion'
% Phase 8 — Simulink 进阶 (新增)
't36_stateflow_basics'
't37_triggered_subsystem'
't38_bus_signals'
't39_model_referencing'
't40_variant_subsystem'
't41_callbacks'
't42_sfunction_basics'
't43_model_advisor'};
outDir = fullfile(fileparts(mfilename('fullpath')), 'docs', 'images');
if ~exist(outDir, 'dir'), mkdir(outDir); end
n = numel(tutorials);
for i = 1:n
name = tutorials{i};
fprintf('\n################################################\n');
fprintf('## [%2d/%2d] %s\n', i, n, name);
fprintf('################################################\n\n');
try
run_one(name);
catch ME
warning('%s 运行失败: %s', name, ME.message);
end
nSaved = save_figures(name, outDir);
fprintf('\n>>> %s 完成,%d 张图已保存到 docs/images/\n', name, nSaved);
if i < n && ~batchStartupOptionUsed
input('>>> 现在可以截图。按回车继续下一课...', 's');
end
close all;
bdclose('all'); % 关闭本课模型,避免窗口越积越多
end
fprintf('\n================================================\n');
fprintf(' 全部 %d 课运行完毕!所有图像保存在 docs/images/\n', n);
fprintf('================================================\n');
end
function run_one(name)
% 在独立工作区中运行教程脚本,
% 这样脚本里的 clear 不会破坏主循环的变量
run(name);
end
function nSaved = save_figures(name, outDir)
figs = flipud(findall(0, 'Type', 'figure'));
nSaved = 0;
for k = 1:length(figs)
if ~isgraphics(figs(k), 'figure'), continue; end
nSaved = nSaved + 1;
file = fullfile(outDir, sprintf('%s_fig%d.png', name, nSaved));
try
exportgraphics(figs(k), file, 'Resolution', 120);
catch
try
saveas(figs(k), file);
catch
fprintf(' [警告] 第 %d 张图保存失败,跳过\n', k);
nSaved = nSaved - 1;
end
end
end
end