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

4 次查看(过去 30 天)
Hello,
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...

采纳的回答

Sebastian K
Sebastian K 2017-5-22
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.
Sebastian
  1 个评论
KIMAE
KIMAE 2017-5-23
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by