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;');
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):
Expression 'configBus' for type of data 'config' did not evaluate to a valid type. Caused by:
Error evaluating MATLAB Function parameter data
'Datatype' in its parent workspace.
Unrecognized function or variable 'configBus'.
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.