00-待填充

simulink模型搭建及代码生成

1 常用模块

1.1 In输入

1.2 Out输出

1.3 goto和from

1.4 constant

1.5 data type conversion数据类型转换

1.6 enable使能模块

1.7 unit delay

1.8 memory

1.9 display

1.10 scope

1.11 bus creator和bus selector

1.12 switch

1.13 signal builder

1.14 State Follow

2 变量设置

2.1 signal 和 parameter相关介绍

2.2 批量设置变量的工具介绍

使用m文件运行程序,读取excel中的数据,将signal和parameter添加到工作空间中

clear all
clear all
clc
% uigetfile的第一个参数,带类型的文件名,可以cell类型;第二个参数对话框的title名称
[filename,pathname] =uigetfile({'*.xlsx';'*.xls'},'Select the Data Dictionary');

if isequal(filename,0)
disp('User selected Cancel')
return
else
disp(['User selected ', fullfile(pathname, filename)]) % fullfile()返回filename文件的路径,[,]连接字符串,disp()显示输出
end
cd(pathname);

[a,b,ad]=xlsread(filename); % xlsread函数读取excel表格,返回,表中数据,表头,表头+表中数据,每个元素为元组cell
%[a,b,ad]=xlsread('lmp_dd.xlsx');
fid = fopen('datafile1.m','w'); % 以‘write’写的方式打开文件datafile1.m没有就会新建一个

ObjectAttribute=ad(1,:); % 取出ad中的第一行元素;  regexprep(t,'\W','')清除空格;isequal函数返回第一个参数和第二个参数匹配的下标
ObIndex=find(cellfun(@(t) isequal(regexprep(t,'\W',''),'Object'),ObjectAttribute)); % cellfun()第一个参数,使用函数调用isequal函数,并把t作为输入参数,第二个参数作为第一个参数的输入参数
NameIndex=find(cellfun(@(t) isequal(regexprep(t,'\W',''),'Name'),ObjectAttribute)); % 返回ad表头中,对应‘Name’元素在元组列表中的下标
ValueIndex=find(cellfun(@(t) isequal(regexprep(t,'\W',''),'Value'),ObjectAttribute));
UnitsIndex=find(cellfun(@(t) isequal(regexprep(t,'\W',''),'Units'),ObjectAttribute));
TypeIndex=find(cellfun(@(t) isequal(regexprep(t,'\W',''),'Type'),ObjectAttribute));
%AccuracyIndex=find(cellfun(@(t) isequal(regexprep(t,'\W',''),'Accuracy'),ObjectAttribute));
MinIndex=find(cellfun(@(t) isequal(regexprep(t,'\W',''),'Min'),ObjectAttribute));
MaxIndex=find(cellfun(@(t) isequal(regexprep(t,'\W',''),'Max'),ObjectAttribute));
%DeclFileIndex=find(cellfun(@(t) isequal(regexprep(t,'\W',''),'DeclFile'),ObjectAttribute));
%DefnFileIndex=find(cellfun(@(t) isequal(regexprep(t,'\W',''),'DefnFile'),ObjectAttribute));
DescriptionIndex=find(cellfun(@(t) isequal(regexprep(t,'\W',''),'Description'),ObjectAttribute));
StorageClassIndex=find(cellfun(@(t) isequal(regexprep(t,'\W',''),'StorageClass'),ObjectAttribute));%列序号
% ObjectAttribute(ObIndex)=[];
% len=length(ObjectAttribute);

DataAttribute=ad(2:end,:); % 将ad中的数据元素的元组读出
 ObNum=numel(DataAttribute)/length(DataAttribute); % 元素总数/烈数 = 每烈的元素个数 = 行数

Excel文件

3 模型生成代码

3.1 生成代码前的设置

3.2 代码生成及查看代码

以前一次项目工作后的小总结,内容算不上高深,但觉得用的时候还是挺有用的。
先填上目录再补充。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值