ImageVerifierCode 换一换
格式:DOC , 页数:7 ,大小:78.51KB ,
资源ID:4683847      下载积分:6 金币
快捷注册下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/4683847.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请

   平台协调中心        【在线客服】        免费申请共赢上传

权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

注意事项

本文(level-2-s函数帮助文件(英文).doc)为本站上传会员【丰****】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

level-2-s函数帮助文件(英文).doc

1、Write Level-2 MATLAB S-Functions About Level-2 MATLAB S-Functions The Level-2 MATLAB® S-function API allows you to use the MATLAB language to create custom blocks with multiple input and output ports and capable of handling any type of signal produced by a Simulink® model, including matrix and

2、 frame signals of any data type. The Level-2 MATLAB S-function API corresponds closely to the API for creating C MEX S-functions. Much of the documentation for creating C MEX S-functions applies also to Level-2 MATLAB S-functions.To avoid duplication, this section focuses on providing information th

3、at is specific to writing Level-2 MATLAB S-functions. A Level-2 MATLAB S-function is MATLAB function that defines the properties and behavior of an instance of a Level-2 MATLAB S-Function block that references the MATLAB function in a Simulink model. The MATLAB function itself comprises a set o

4、f callback methods (see Level-2 MATLAB S-Function Callback Methods) that the Simulink engine invokes when updating or simulating the model. The callback methods perform the actual work of initializing and computing the outputs of the block defined by the S-function. To facilitate these tasks, t

5、he engine passes a run-time object to the callback methods as an argument. The run-time object effectively serves as a MATLAB proxy for the S-Function block, allowing the callback methods to set and access the block properties during simulation or model updating. About Run-Time Objects When th

6、e Simulink engine invokes a Level-2 MATLAB S-function callback method,it passes an instance of the Simulink.MSFcnRunTimeBlock class to the method as an argument. This instance, known as the run-time object for the S-Function block, serves the same purpose for Level-2 MATLAB S-function callback metho

7、ds as the SimStruct structure serves for C MEX S-function callback methods. The object enables the method to provide and obtain information about various elements of the block ports, parameters,states, and work vectors. The method does this by getting or setting properties or invoking methods of the

8、 block run-time object. See the documentation for the Simulink.MSFcnRunTimeBlock class for information on getting and setting run-time object properties and invoking run-time object methods. Run-time objects do not support MATLAB sparse matrices. For example, if the variable block is a run-time obj

9、ect, the following line in a Level-2 MATLAB S-function produces an error: block.Outport(1).Data = speye(10); where the speye command forms a sparse identity matrix. Note  :Other MATLAB programs besides MATLAB S-functions can use run-time objects to obtain information about a MATLAB S-function in

10、a model that is simulating. See Access Block Data During Simulation in Using Simulink for more information. Level-2 MATLAB S-Function Template Use the basic Level-2 MATLAB S-function template msfuntmpl_basic.mmsfuntmpl_basic.m to get a head start on creating a new Level-2 MATLAB S-function. The te

11、mplate contains skeleton implementations of the required callback methods defined by the Level-2 MATLAB S-function API. To write a more complicated S-function, use the annotated template msfuntmpl.mmsfuntmpl.m. To create a MATLAB S-function, make a copy of the template and edit the copy as necessa

12、ry to reflect the desired behavior of the S-function you are creating. The following two sections describe the contents of the MATLAB code template. The section Example of Writing a Level-2 MATLAB S-Function describes how to write a Level-2 MATLAB S-function that models a unit delay. Level-2 MATLAB

13、 S-Function Callback Methods The Level-2 MATLAB S-function API defines the signatures and general purposes of the callback methods that constitute a Level-2 MATLAB S-function. The S-function itself provides the implementations of these callback methods. The implementations in turn determine the bl

14、ock attributes (e.g., ports, parameters, and states) and behavior (e.g., the block outputs as a function of time and the block inputs, states, and parameters). By creating an S-function with an appropriate set of callback methods, you can define a block type that meets the specific requirements of y

15、our application. A Level-2 MATLAB S-function must include the following callback methods: A setup function to initializethe basic S-function characteristics An Outputs function to calculatethe S-function outputs Your S-function can contain other methods, depending on the requirements of the bloc

16、k that the S-function defines. The methods defined by the Level-2 MATLAB S-function API generally correspond to similarly named methods defined by the C MEX S-function API. For information on when these methods are called during simulation, see Process View in Simulink Engine Interaction with C S-Fu

17、nctions. For instructions on how to implement each callback method, see Write Callback Methods. The following table lists all the Level-2 MATLAB S-function callback methods and their C MEX counterparts. Level-2 MATLAB Method Equivalent C MEX Method setup (see Using the s

18、etup Method) mdlInitializeSizes CheckParameters mdlCheckParameters Derivatives mdlDerivatives Disable mdlDisable Enable

19、 mdlEnable InitializeConditions mdlInitializeConditions Outputs mdlOutputs PostPropagationSetup mdlSetWorkWidths ProcessParameters

20、 mdlProcessParameters Projection mdlProjection SetInputPortComplexSignal mdlSetInputPortComplexSignal SetInputPortDataType mdlSetInputPortDataType SetInputPortDimensions

21、 mdlSetInputPortDimensionInfo SetInputPortDimensionsModeFcn mdlSetInputPortDimensionsModeFcn SetInputPortSampleTime mdlSetInputPortSampleTime SetInputPortSamplingMode mdlSetInputPortFrameData SetOutputPortComple

22、xSignal mdlSetOutputPortComplexSignal SetOutputPortDataType mdlSetOutputPortDataType SetOutputPortDimensions mdlSetOutputPortDimensionInfo SetOutputPortSampleTime mdlSetOutputPortSampleTime

23、 SimStatusChange mdlSimStatusChange Start mdlStart Terminate mdlTerminate Update mdlUpdate WriteRTW

24、 mdlRTW Using the setup Method The body of the setup method in a Level-2 MATLAB S-function initializes the instance of the corresponding Level-2 MATLAB S-Function block. In this respect, the setup method is similar to the mdlInitializeSizes and mdlInitializeSampleTimes callback method

25、s implemented by C MEX S-functions. The setup method performs the following tasks: Initializing the number of input and output portsof the block. Setting attributes such as dimensions, data types,complexity, and sample times for these ports. Specifying the block sample time. See Speci

26、fy Sample Time in Using Simulink for more information on how to specify valid sample times. Setting the number of S-function dialog parameters. Registering S-function callback methods by passing the handles of local functions in the MATLAB S-function to the RegBlockMethod metho

27、d of the S-Function block's run-time object. See the documentation for Simulink.MSFcnRunTimeBlock for information on using the RegBlockMethod method. Example of Writing a Level-2 MATLAB S-Function The following steps illustrate how to write a simple Level-2 MATLAB S-function. When applicable,t

28、he steps include examples from the S-function example msfcn_unit_delay.mmsfcn_unit_delay.m used in the model msfcndemo_sfundsc2msfcndemo_sfundsc2. All lines of code use the variable name block for the S-function run-time object. 1.Copy the Level-2 MATLAB S-function template msfuntmpl_basic.mmsf

29、untmpl_basic.m to your working folder. If you change the file name when you copy the file, change the function name in the function line to the same name. 2.Modify the setup method to initialize the S-function's attributes. For this example: Set the run-time object's NumInputPorts and NumOutputPor

30、ts properties to 1 in order to initialize one input port and one output port. Invoke the run-time object's SetPreCompInpPortInfoToDynamic and SetPreCompOutPortInfoToDynamic methods to indicate that the input and output ports inherit their compiled properties (dimensions, data type, complexity, and

31、sampling mode)from the model. Set the DirectFeedthrough property of the run-time object's InputPort to false in order to indicate the input port does not have direct feedthrough. Retain the default values for all other input and output port properties that are set in your copy of the template file.

32、 The values set for the Dimensions, DatatypeID, and Complexity properties override the values inherited using the SetPreCompInpPortInfoToDynamic and SetPreCompOutPortInfoToDynamic methods. Set the run-time object's NumDialogPrms property to 1 in order to initialize one S-function dialog parameter.

33、 Specify that the S-function has an inherited sample time by setting the value of the runtime object's SampleTimes property to [-1 0]. Call the run-time object's RegBlockMethod method to register the following four callback methods used in this S-function. PostPropagationSetup InitializeCond

34、itions Outputs Update Remove any other registered callback methods from your copy of the template file. In the calls to RegBlockMethod, the first input argument is the name of the S-function API method and the second input argument is the function handle to the associated local function in th

35、e MATLAB S-function. The following setup method from msfcn_unit_delay.m performs the previous list of steps: function setup(block) %% Register a single dialog parameter block.NumDialogPrms = 1; %% Register number of input and output ports block.NumInputPorts = 1; block.NumOutputPorts =

36、1; %% Setup functional port properties to dynamically %% inherited. block.SetPreCompInpPortInfoToDynamic; block.SetPreCompOutPortInfoToDynamic; %% Hard-code certain port properties block.InputPort(1).Dimensions = 1; block.InputPort(1).DirectFeedthrough = false; block.OutputPort(

37、1).Dimensions = 1; %% Set block sample time to [0.1 0] block.SampleTimes = [0.1 0]; %% Register methods block.RegBlockMethod('PostPropagationSetup',@DoPostPropSetup); block.RegBlockMethod('InitializeConditions',@InitConditions); block.RegBlockMethod('Outputs', @Output);

38、 block.RegBlockMethod('Update', @Update); If your S-function needs continuous states, initialize the number of continuous states in the setup method using the run-time object's NumContStates property. Do not initialize discrete states in the setup method. 3.Initialize the discret

39、e states in the PostPropagationSetup method. A Level-2 MATLAB S-function stores discrete state information in a DWork vector. The default PostPropagationSetup method in the template file suffices for this example. The following PostPropagationSetup method from msfcn_unit_delay.m, named DoPostPropSe

40、tup,initializes one DWork vector with the name x0. function DoPostPropSetup(block) %% Setup Dwork block.NumDworks = 1; block.Dwork(1).Name = 'x0'; block.Dwork(1).Dimensions = 1; block.Dwork(1).DatatypeID = 0; block.Dwork(1).Complexity = 'Real'; block.Dwork(1).

41、UsedAsDiscState = true; If your S-function uses additional DWork vectors,initialize them in the PostPropagationSetup method, as well (see Using DWork Vectors in Level-2 MATLAB S-Functions). 4. Initialize the values of discrete and continuous states or other DWork vectors in the InitializeCondition

42、s or Start callback methods. Use the Start callback method for values that are initialized once at the beginning of the simulation. Use the InitializeConditions method for values that need to be reinitialized whenever an enabled subsystem containing the S-function is reenabled. For this example, us

43、e the InitializeConditions method to set the discrete state's initial condition to the value of the S-function's dialog parameter. For example, the InitializeConditions method in msfcn_unit_delay.m is: function InitConditions(block) %% Initialize Dwork block.Dwork(1).Data = block.DialogPrm

44、1).Data; For S-functions with continuous states, use the ContStates run-time object method to initialize the continuous state date. For example: block.ContStates.Data(1) = 1.0; 5.Calculate the S-function's outputs in the Outputs callback method. For this example, set the output to the current v

45、alue of the discrete state stored in the DWork vector. The Outputs method in msfcn_unit_delay.m is: function Output(block) block.OutputPort(1).Data = block.Dwork(1).Data; 6.For an S-function with continuous states, calculate the state derivatives in the Derivatives callback method. Run-time

46、objects store derivative data in their Derivatives property. For example, the following line sets the first state derivative equal to the value of the first input signal. block.Derivatives(1).Data = block.InputPort(1).Data; This example does not use continuous states and, therefore, does not imple

47、ment the Derivatives callback method. 7. Update any discrete states in the Update callback method. For this example, set the value of the discrete state to the current value of the first input signal. The Update method in msfcn_unit_delay.m is: function Update(block) block.Dwork(1).Data = bl

48、ock.InputPort(1).Data; 8.Perform any cleanup, such as clearing variables or memory, in the Terminate method. Unlike C MEX S-functions, Level-2 MATLAB S-function are not required to have a Terminate method. For information on additional callback methods, see Level-2 MATLAB S-Function Callback Meth

49、ods. For a list of run-time object properties, see the reference page for Simulink.MSFcnRunTimeBlock and the parent class Simulink.RunTimeBlock. Instantiating a Level-2 MATLAB S-Function To use a Level-2 MATLAB S-function in a model, copy an instance of the Level-2 MATLAB S-Functionblock into the

50、model. Open the Block Parameters dialog box for the block and enter the name of the MATLAB file that implements your S-function into the S-function name field. If your S-function uses any additional parameters, enter the parameter values as a comma-separated list in the Block Parameters dialog box P

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服