Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Simulink with Object Oriented code

Subject: Simulink with Object Oriented code

From: Thomas Clark

Date: 8 Sep, 2013 06:48:09

Message: 1 of 3

Hi,
I'm in straight MATLAB at the moment, putting together a toolbox for aerodynamic load simulation.

I'm structuring one of my key simulation tools using a set of Object classes (one for blade response, one to handle numerical simulation, etc).

Simulation is in the time domain, and includes timestepping functions (e.g. where I can step forward in time from a known performance by a known increment dt and calculate the new thrust, torque etc).

Ultimately, I see a use where this class method can be called from Simulink as part of the timestepping process within a wider model. However, I wanted to check:

- Has anyone been able to do that?
- Is there anything special I need to do to make the object(s) persist between calls?
- Are MATLAB Objects handled by Simulink? (i.e. can I return an object as a variable to Simulink to avoid doing something weird like keeping the object in a global workspace between function calls from a Sim block?)
- Is there anything special I'd need to to to initialise a class object within Simulink (Other than construct it as normal)?

Has anyone got any recommendations for best practises while doing this?

Cheers,

Tom

Subject: Simulink with Object Oriented code

From: Phil Goddard

Date: 8 Sep, 2013 15:21:09

Message: 2 of 3

Although this can be done, be prepared for considerable frustration as Simulink is not designed to work with MATLAB objects.

You will not be able to pass MATLAB objects down a Simulink signal.
(This can be done with custom C data types, using c-mex S-functions, but not with m-code S-functions.)
With a little work you can pass the handle of an object down a signal (as it can be mapped to a double, and your m-code S-Functions will need to know that the double represents a handle and know what to do with it) , but you will need to store the object somewhere (global memory, workspace, userdata) which you indicate that you (quite rightly) want to avoid.

Phil.

Subject: Simulink with Object Oriented code

From: Thomas Clark

Date: 8 Sep, 2013 17:07:06

Message: 3 of 3

Phil,

Thanks, very helpful and food for thought. I guess if I store in global memory, I wouldn't need to send a handle back and forth, just reference the global variable name from my m code.

I'll use that as a temporary workaround, and try to find something a bit more robust for the longer term (I certainly couldn't deploy that to clients for example). Maybe once I get past prototyping I'll fling it all into C.

What a pain. Feature request to TMW coming up!

Thanks for your help,

Tom Clark





"Phil Goddard" <phil@goddardconsulting.ca> wrote in message <l0i4l5$sqm$1@newscl01ah.mathworks.com>...
> Although this can be done, be prepared for considerable frustration as Simulink is not designed to work with MATLAB objects.
>
> You will not be able to pass MATLAB objects down a Simulink signal.
> (This can be done with custom C data types, using c-mex S-functions, but not with m-code S-functions.)
> With a little work you can pass the handle of an object down a signal (as it can be mapped to a double, and your m-code S-Functions will need to know that the double represents a handle and know what to do with it) , but you will need to store the object somewhere (global memory, workspace, userdata) which you indicate that you (quite rightly) want to avoid.
>
> Phil.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us