Ali
Ali

Reputation: 31

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

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.

Upvotes: 3

Views: 30695

Answers (2)

Salomon
Salomon

Reputation: 1

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

Upvotes: 0

Praetorian
Praetorian

Reputation: 109079

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.

Upvotes: 7

Related Questions