How can I call an m file in Simulink and put it to a block in my model?

北城以北 提交于 2019-12-12 17:07:18

问题


How can I call an m file in Simulink and put it to a block in my model (without using an S function)? Does anybody have an idea? I'd really appreciate it.


回答1:


If you're trying to apply a user-defined MATLAB function to Simulink signals, there are a few different ways to do this, depending on your objective. All options are available within the User-Defined Functions section of the Simulink library.

  • Use the MATLAB function block if you intend to generate code from your model. This block does have restrictions, the entire gamut of built-in MATLAB functions is not available.

  • Use the Interpreted MATLAB function block if you don't care about code generation, this block can make use of any functions.

  • Use the Fcn block if your m-file is trivial and contains a simple expression operating on the inputs. In this case you can type the expression directly into the block dialog and reference the input / output signals as shown in the documentation.




回答2:


MATLAB Fcn block is the best solution to embed M-function file into Simulink model. However, be cautious which version of MATLAB you are using, e.g., with later versions of MATLAB Function Block can be implemented with M-function file with %#codegen and C compiler need to be with your MATLAB package. Good luck



来源:https://stackoverflow.com/questions/7405780/how-can-i-call-an-m-file-in-simulink-and-put-it-to-a-block-in-my-model

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!