此脚本可以提取simulink的inport与outport的信号名称、数据类型等信息并将其导出到excel表中。
clear;
str1 = 'ASW';
ASD = {''};
xlswrite('lingshi',ASD,'sheet1','A1:I1000'); %清空表格
biaotou = {'信号名称','描述','数据类型','访问方式','源/目的','单位','分辨率','最小值','最大值'};
xlswrite('lingshi',biaotou,'sheet1','A1'); %写入表头
Outport=find_system(gcs,'SearchDepth',1,'FindAll','on','BlockType','Outport'); %获取模型输出端口信息
Inport=find_system(gcs,'SearchDepth',1,'FindAll','on','BlockType','Inport'); %获取模型输入端口信息
for i = 2:length(Inport) %输入口第一个为激活信号,所以从2开始
modelname = get_param(Inport(i),'Name'); %名称
modelPath = get_param(Inport(i), 'Description'); %描述
modeldata = get_param(Inport(i),"DataType"); %信号类型
modeltype = get_param(Inport(i),"BlockType"); %输入or输出
result = [str1, modeltype];
modelorgin = get_param(Inport(i),"Unit"); %单位
modelmin = get_param(Inport(i),"OutMin"); %最小值
modelmax = get_param(Inport(i),"OutMax"); %最大值
model = {modelname,modelPath,modeldata,result,{' '},modelorgin,{' '},modelmin,modelmax}; %生成元组
mRowRange = num2str(i); %数组长度转化为字符串
AB = strcat('A', mRowRange); %拼接表格输入位置信息
xlswrite('lingshi',model,'sheet1',mRowRange); %将元组信息写入表格
end
for j = 1:length(Outport)
modelname = get_param(Outport(j),'Name');
modelPath = get_param(Outport(j), 'Description');
modeldata = get_param(Outport(j),"DataType");
modeltype = get_param(Outport(j),"BlockType");
result = [str1, modeltype];
modelorgin = get_param(Outport(j),"Unit");
modelmin = get_param(Outport(j),"OutMin");
modelmax = get_param(Outport(j),"OutMax");
model = {modelname,modelPath,modeldata,result,{' '},modelorgin,{' '},modelmin,modelmax};
mRowRange = num2str(i+j);%数组长度转化为字符串
AB = strcat('A', mRowRange);
xlswrite('lingshi',model,'sheet1',mRowRange);
end
warndlg('数据生成成功.', '提示');