simulink与matlab的交互

  1. Simulink调用m文件

S-function或者matla fcn

  1. Simulink与工作空间的交互

Yout

  1. .m文件调用simulink模块

[ t, x, y ] = sim( model, timespan, options, ut)
[ t, x, y1, y2, …, yn] = sim( model, timespan, options, ut)

simOut =sim('model',ParameterName1',Value1,'ParameterName2', Value2...);
simOut = sim('model', ParameterStruct);
simOut = sim('model', ConfigSet);

m文件里调用模型mdl关键是用sim命令。

[ t, x, y ] = sim( model, timespan, options, ut)

[ t, x, y1, y2, …, yn] = sim( model, timespan, options, ut)

1model:需要进行仿真的系统模型框图名称;

2timespan:系统仿真的时间范围(起始至终止时间),可有如下形式:

tFinal:设置仿真终止时间。仿真起始时间默认为0

[tStarttFinal]:设置起始时间(tStart)与终止时间(tFinal);

[tStartOutputTimestFinal]:设置起始时间(tStart)与终止时间(tFinal),并且设置仿真返回的时间向量[tStartOutputTimestFinal],其中tStartOutputTimestFinal必须按照升序排列。

3options:由simset命令所设置的除仿真时间外的仿真参数;

4ut:表示系统模型顶层的外部可选输入。ut可以是MATLAB 函数。可以使用多个外部输入ut1ut2、…。

5t:返回系统仿真的时间向量。

6x:返回系统仿真的状态变量矩阵。

7y:返回系统仿真的输出矩阵。按照顶层输出Outport模块的顺序输出。如果输出信号为向量输出,则输出信号具有与此向量相同的维数。

8y1,…,yn:返回多个系统仿真的输出。

改变模型输入参数的demo,同时不影响原来的mdl文件

>t=0:0.1:10; t=t’; u=sin(t); sim_input=[t, u];

>[tout1, x1, yout1]=sim(command_in_out, 10); %使用Simulink仿真参数对话框中的workspace I/O MATLAB 工作空间中获得输入信号

>u=cos(t);

>ut=[t, u]; %改变系统输入信号

>>[tout2, x2, yout2]=sim(‘command_in_out’, 10, [], ut);

 

 

 

 

 

 

 

 

 

 

公共参数,所有块共有,如:

特有参数,块本身自己的参数;

掩码参数,它们是描述屏蔽块的参数;

  1.  get_param and set_param 用法:

首先:open_system('model')或load_system(‘modelname’)

paramValue = get_param('模型名/块名','参数名')

set_param('模型名/块名','参数名','该参数要设的值')

set_param(Object,ParameterName,Value,...ParameterNameN,ValueN)

如:set_param('myModel/My Constant','Value','25')

另外:

Block中的参数,可以设置为常量,工作空间中的变量,或函数,如:

 

You can set a block parameter value to an expression that calls MATLAB functions and operators such as sin and max. You can also call your own custom functions that you write on the MATLAB path.

又如:

 

  1. 如何参看block的参数

Double-click the block.

Right-click the block and select Block Parameters. (适用于封装模块)

  1. 各block的参数名称表格(有的参数名称和双击改模块出现的名称不一致,这时需要查表)

表: 查找帮助文档 Block-Specific Parameters 即可见。

 

 

 

 

 

 

  • 5
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值