Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

m-file in Simulink

m-file in Simulink

m-file in Simulink


I would like to include m-file into Simulink workspace. Should I use 'Level-2 M-file S-Function' block, if yes, how it must be used if I want to include two variables, one is a number and second is a text.
I could simply use m-file in Matlab command window and calculate what I need, but as I would like to include m-file into Simulink model.

RE: m-file in Simulink

use an embedded function
If you don't have the toolbox you can use an S-function. Although, you would have to convert your M-code to C-code...


RE: m-file in Simulink

"you would have to convert your M-code to C-code... " No you don't have to do that. S functions can be native m.

Another way of doing that is to create a user function block, which would appear to limit you to one input and one output, but I see no reason why you couldn't MUX multiple inputs into a vector. I'll try that when I am next on a suitable box.



Greg Locock

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies  http://eng-tips.com/market.cfm?

RE: m-file in Simulink

Thanks Greg, I'm looking for your results here.

RE: m-file in Simulink

Yes, Greg you are right. My apologies. I remember using m-file S functions as well to solve nonlinear DE's in Simulink.
The"user function block" is the same as an "embedded function block". Which can handle any amount of inputs and outputs all in m-code.
Actually this is much simpler than an S-fcuntion for bergineers.
But, S-functions are far more powerful. (embedded only allows some external functions to be utilized) (whereas an m-file s-function can solve any n-order runge kutta DE as well as basic computations. ect.  


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close