How can I initialize a bus with a "stringtype" field?

7 Ansichten (letzte 30 Tage)
I am using MATLAB R2022a and I have a "Bus" type which contains some string fields (data type "stringtype(XX)", where XX is a known maximum length). I need to initialize this bus type in my model; however, if I try to use a "Constant" block with a zero value to initialize the bus, I receive the following error:
The 'Constant' block cannot produce a non-virtual bus output containing strings. A non-virtual bus containing strings is connected to output port 0 of block '<model_name>/Constant'.
Is there a way to initialize buses with stringtype fields, either using the "Constant" block or by another method?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 18 Aug. 2023
Unfortunately, as documented in the following documentation page:
there is no direct way to initialize a bus with a string field using a "Constant" block in Simulink.
One way in which you could get around this limitation would be by using "String Constant" blocks to initialize the string bus fields, then combining those fields with the non-string bus fields using a "Bus Creator" block which outputs your desired bus type:
An additional approach you could consider to avoid completely reconstructing the buses in Simulink would be to create a version of your original bus with only the non-string signals, initialize that bus using a "Constant" block, then combine that bus with all the string signals in a "Bus Creator" block to create the final bus type. In other words, your final bus would consist of one field which is a nested bus of the non-string fields and any number of additional string fields:
The benefit of this approach over the previous is that you would not need to separately initialize each of the signals in your bus and reconstruct them into the output bus type; instead, you could reuse most of the existing bus (with the string fields removed) and just nest it within the output bus, which simplifies the layout.

Weitere Antworten (0)

Kategorien

Mehr zu Event Functions finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by