Attach mixed data types Buses to MATLAB Function Blocks

20 Ansichten (letzte 30 Tage)
Dimitri
Dimitri am 31 Jul. 2025
Beantwortet: Alan am 18 Aug. 2025
Hello!
I've check how to attached buses to MATLAB Function Blocks in Simulink model from here: https://nl.mathworks.com/help/simulink/ug/attach-bus-signals-to-matlab-function-blocks.html
But in the example, all busses were created in a different manner than in my initial model.
To illistrate the problem, I've created the model (in real model I have much more elements)
I've tried to do the same, but got an error:
Input port cannot accept mixed data types. 'Input Port 1' of 'untitled/MATLAB Function' expects a signal with unique data type. However, it is driven by a signal with elements of differing data types.
Component:Simulink | Category:Model error
My question is: how can I send mixed data type buses to MATLAB Function blocks without redefining all existing bus structures?
Please find the example model attached.

Akzeptierte Antwort

Alan
Alan am 18 Aug. 2025
Hi Dimitri,
From my understanding, you would like to make the ports of the “MATLAB Function” block to be compatible with buses containing mixed data types.
It seems like in Simulink R2022b, the port types are not automatically assigned the appropriate bus types. As a workaround, perform the following steps:
  • Put the bus selector into a subsystem block named “SubsystemA”. This would help in creating “Simulink.Bus” object.
  • Temporarily disable the “MATLAB Function” block.
  • Go inside “SubsystemA” and select outport “<WarningMsg>”, then navigate to the MATLAB Command line and execute the following command:
>> Simulink.Bus.createObject(bdroot, gcb);
  • Perform the previous step for “<ErrorMsg>”.
  • Re-enable the “MATLAB Function” and navigate to its section in the “Model Editor” window:
  • Set the type of “warnings” to “Bus: WarningMsg”.
  • Set the type of “errors” to “Bus: ErrorMsg”.
  • Set the type of “itemMsg” to “Inherit: Same as Simulink”.
  • Save the data dictionary “bus2MATLAB”.
  • Navigate to the “MATLAB Function” block and add the following line to the beginning of the function:
itemMsg = uint16(0);
  • Save the model.
This should resolve the errors. I have also attached a modified model for reference.
Regards,
Alan

Weitere Antworten (0)

Kategorien

Mehr zu Programmatic Model Editing finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by