You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Simulink模型的所有输入输出名称导出到Excel文件

Simulink模型输入输出名称导出到Excel脚本实现

以下是可直接复用的完整脚本,能提取Simulink模型的所有输入、输出端口名称并导出到Excel文件:

% 替换为你的Simulink模型文件名(带.slx后缀)
model_name = 'your_model.slx';
% 替换为要导出的Excel文件名
excel_file = 'simulink_io_export.xlsx';

% 打开目标模型
open_system(model_name);

% 查找所有输入端口(包含子系统、掩码内的端口)
inports = find_system(gcs, 'BlockType', 'Inport', ...
    'LookUnderMasks', 'on', 'FollowLinks', 'on');
% 查找所有输出端口(包含子系统、掩码内的端口)
outports = find_system(gcs, 'BlockType', 'Outport', ...
    'LookUnderMasks', 'on', 'FollowLinks', 'on');

% 提取输入端口名称并过滤空值
input_names = cell(length(inports), 1);
for idx = 1:length(inports)
    input_names{idx} = get_param(inports{idx}, 'Name');
end
input_names = input_names(~cellfun(@isempty, input_names));

% 提取输出端口名称并过滤空值
output_names = cell(length(outports), 1);
for idx = 1:length(outports)
    output_names{idx} = get_param(outports{idx}, 'Name');
end
output_names = output_names(~cellfun(@isempty, output_names));

% 整理导出数据:补全行数以对齐输入输出列
max_rows = max(length(input_names), length(output_names));
export_data = cell(max_rows, 2);
export_data(1:length(input_names), 1) = input_names;
export_data(1:length(output_names), 2) = output_names;

% 写入Excel文件,添加表头
xlswrite(excel_file, {'输入端口名称', '输出端口名称'}, 'Sheet1', 'A1');
xlswrite(excel_file, export_data, 'Sheet1', 'A2');

% 关闭模型(可选操作)
close_system(model_name);

disp('导出完成!');

关键说明

  • 替换脚本开头的model_name和excel_file为你的实际文件名
  • LookUnderMasks和FollowLinks参数确保捕获子系统、掩码模块内的输入输出端口,若不需要此类端口,删除这两个参数即可
  • 自动过滤空名称,避免Excel中出现无效空行
  • 表头与数据分开写入,导出的Excel结构更清晰直观

内容的提问来源于stack exchange,提问作者Amiens

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 07:07:11