views:

667

answers:

3

How do I convert from a function that I have written as an m-file into a block in Simulink model? I couldn't find anything on Google that tells me how to do that easily, so it would be much appreciated if any of the readers here can help point me in the right direction.

+2  A: 

You want to create an "S-Function":

http://www.mathworks.com/access/helpdesk/help/toolbox/simulink/sfg/ug_intropage.html

seanmac7577
+3  A: 

Perhaps you're looking for an Embedded MATLAB Function Block? Here's an example of how to create one.

gnovice
That's actually what I end up doing.
stanigator
+3  A: 

Like the previous answers have stated, there are multiple ways of doing this, and which way you pick depends on what you need to do.

  1. If you need to support Real-Time Workshop code generation for your M code, you probably want to use the Embedded MATLAB function block that gnovice recommended. There are some restrictions on what MATLAB operations are supported, so read the doc. To call existing MATLAB code, you should probably read the doc on extrinsic functions.

  2. If you have no RTW requirements, you can use the MATLAB Fcn block.

  3. Another option is to use an M-file s-function which gives you the ability to generate RTW code if you need to (although you would have to write TLC for the block).

MikeT

related questions