How to use Simulink.B​us.createM​ATLABStruc​t() in a Matlab-Function

3 views (last 30 days)
I have got a non-virutal Bus defined in Simulink (exported / saved to the file "testBusStruct.mat"). This Bus is connected to a Matlab-Function. In that Matlab-Function I want e.g. to return instances of this struct to put them onto the Bus.
Unfortunately, Simulink.Bus.createMATLABStruct('BusObject') does not work. The Matlab-Function complains already about "Simulink" which is not found. If I include Simulink as extrinsic (which is probably not the right way to use it), then it complains about "Dot notation on function call is not allowed as return value" which does not make any sense at all. The BusObject, however, is already visible in the Matlab Workspace as variable, but I cannot allocate a new struct based on the Bus-structure.
I already tried: %coder.extrinsic('Simulink.Bus') %coder.extrinsic('Simulink.Bus.createMATLABStruct') %temp = load('testBusStruct.mat') currentStepBusStruct = Simulink.Bus.createMATLABStruct('BusObject') %currentStepBusStruct = BusObject
Nothing helps, and I cannot find the solution on your website. The documentation for Simulink.Bus.createMATLABStruct does NOT describe its limitations and its scope - according to the documentation it should work...

Accepted Answer

Sebastian Kammer
Sebastian Kammer on 22 May 2017
Hi there,
The MATLAB Function block offers limited support for classes and functions that are available to users in the base MATLAB environment. This is because the MATLAB Function block is typically used with code generation, and not all MATLAB methods and functions are supported for code generation.
For instance, if you take a look at the documentation page that lists the functions and objects that are supported for code generation, you will notice that none of the Simulink API objects and functions (e.g., Simulink.Bus) are listed here.
For creating structures in a MATLAB Function block, please refer to the relevant documentation page that describes the recommended workflow.
I hope this helps.
  1 Comment
KIMAE on 23 May 2017
Thank you, yes this indeed helps. For beginners the interface between Simulink and Matlab is not easy to understand. Seems like any code-generating blocks are not suitable for my problem.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!