I have created a class in Python. In my application this class is a kind of lookup table.
Here is a sample class to illustrate the topic :
class ExampleClass:
def __init__(self, var1):
self.prop1 = var1
def get_property(self):
return self.prop1
Matlab offers the ability to call Python modules directly within the Matlab environment (see Matlab docs)
One calls Python like :
>>> py.importlib.import_module("ExampleClass")
>>> x = py.ExampleClass.ExampleClass(1)
>>> x.get_property()
ans =
1
What I would like to do is to make x
available in Simulink m-function blocks in order to call get_property()
from all the m-function blocks. Note that the creation of x
is computationally expensive, therefore I want to load it in the workspace once when initializing the simulation.
What I tried so far :
I tried passing my ExampleClass
to the m-functions via a mask parameter, but I get an error :
Error:Expression 'object name' for type of data 'x' did not evaluate to a valid type.
Which is understandable because Simulink does not allow to use datatypes other than int
, double
and other standard data types.
Is there a way around to be able to call x.get_property()
from my m-functions ?