Bus with sub buses with wrong type (bug ?)

20 次查看(过去 30 天)
Hello everyone!
(Last updated response : 05/08/2025)
Settings
I am facing a very strange issue. Here is my situation : I am creating a Simulink model that call a complex Matlab function. The function, name MD, is take a nested struct as an input, named config. The struct will be updated meaning adding fields (only on the first call), and updated value.
After some research, I have understood that the best way to solve my problem is to create a type 'bus :configbus', via
Simulink.Bus.createObject(config)
evalin('base', 'configbus = slBus1;');
clear("slBus1")
Then, in Simulink I have my Matlab function block, linked to Data Store Read / write for interfacing the config input. This is for the setup.
Adding fields
To solve the fact that on the first call I am adding fields, I run once the function MD, before the simulation and creating the bus, to get all the correct field. I am open to better solution that this bit if you have any.
Errors encounter
However, when configuring the Data Store Memory with the Initial value I get the following error (error1):
  • Invalid setting in 'path to Data Store Read' for parameter 'InitialValue'.
I am trying the following combination:
  • Inital Value : config
  • type : Bus:configBus.
(my function as the input define as the correct type and there is no issue there)
When I run my model I get the error (error2):
Error using Leia_main (line 47)
Expression 'configBus' for type of data 'config' did not evaluate to a valid type.
Caused by:
Error using Leia_main (line 47)
Error using Leia_main (line 47)
Error evaluating MATLAB Function parameter data
'Datatype' in its parent workspace.
Error using Leia_main (line 47)
Unrecognized function or variable 'configBus'.
Error using Leia_main (line 47)
Variable 'configBus' does not exist.
Suggested Actions:
• Load a file into base workspace. - Fix
• Create a new variable. - Fix
Which is really wierd, since it seems that Matlab is confusing the type and the variable. But I have checked and everything seems to be declare as it should.
My investigation
When I look at my top bus definition it do not seems that field corresponding to subbuses are mapped properly. Even though the correct bus type exist.
Here is an example :
SK_requirement is supposed to be of type bus: SK_requirement but is of type SK_requirement which I don't know what type it points to.
And if I set it correctly I get :
Is there any reason why this is behaving like this ? I would expect that the configbus declartion to be correctly typed. (I will try to manually set the good type and see if there is any improvement). My naive guess is that it might solve error1, but not sure.
05/08/2025 adds : it turns out that putting the correct display type is not working either. However, when playing with the Type Editor, MATLAB seems to know that it is pointing to the right bus type.
I have prune my structure until it works. And to be working I need to remove all the variable with type string, type char. Double, and boolean seems to work.
Questions
1) Is there a better way to create the top level bus ? Or is it just a bug ?
2) Do you have any idea for error1 ?
3) Do you have any idea for solutioning error2 ?
Information
Runing matlab25a without the last update. Using MacOS with Apple chip.
Thank you in advance for your insights.

采纳的回答

Emil
Emil 2025-8-8,7:07
So I have figured it out the answer I need.
1° For generating the top level bus, it is actually working fine. It is not the expected name for the type Simulink use later one. It works fine.
2° Error1 was due that Memory block do not support string or char as one of its field. The work around is to either don't use them, or convert them to number, or use a class declaration as such (more elegant I think since you keep the name) :
classdef Start_End_option < Simulink.IntEnumType
enumeration
option1 (1)
options21 (2)
options776 (3)
end
end
And then you use in your structure that way :
config.Start_End_option. Start_end_option.options21
3° Was just a typo, configBus instead of configbus...
There you go. I hope your code journey goes well!

更多回答(1 个)

Sameer
Sameer 2025-8-1
This type of error occurs when the data type assigned to one of the elements of the Bus is not a supported data type in Simulink.
Please refer to the following link, that lists the data types supported by Simulink:
  3 个评论
Emil
Emil 2025-8-5,14:21
I have also found that if I have string in my structure initially, the error1 will appear. If I remove the field it works
Emil
Emil 2025-8-5,14:42
But having a boolean work like a charm.
To recap : on error1 (the initialisation of the Data Store Memory block) : work if there is only the type double and boolean in it. NO field with string or char will work.

请先登录,再进行评论。

类别

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

产品


版本

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by