Accessing Structure Variables in Simulink Using setparam

2 views (last 30 days)
How can I programmatically access Simulink bus objects created from matlab structures using setparam? Our goal is to update the matlab structure “values only” and send these to the Simulink bus on the target without rebuilding. I have not been able to figure this out.
Here is my example: I have built a structure in the model workspace using matlab code, struc, and create a bus using “Simulink.Bus.createObject(struc)”. Figure 1: Model Explorer View of “Model Workspace”
Figure 2: Workspace View and Model Explorer view of created “Base Workspace”
After building the code and sending to target I want to be able to update the parameters of the structure using matlab command line using setparam or some other variant.
Figure 3: I can see the param tags in Simulink explorer for the “struc” and I can add the "struc" params to panel controls in simulink explorer.
Using this information I tried to programmatically update the parameter values. I could not get the syntax to work with these commands:
>> setparam(tg,'sturctconst','/struc(1).layer(1).one',2)
Invalid parameter: "sturctconst//struc(1).layer(1).one"
>> setparam(tg,'sturctconst','struc(1).layer(1).one',2)
Invalid parameter: "sturctconst/struc(1).layer(1).one"
>> setparam(tg,'sturctconst','struc.layer.one',2)
Invalid parameter: "sturctconst/struc.layer.one"
>> setparam(tg,'Parameter','struc(1).layer(1).one',2)
Invalid parameter: "Parameter/struc(1).layer(1).one"
>> setparam(tg,'','struc(1).layer(1).one',2)
Invalid parameter id
>> setparam(tg,' ','struc(1).layer(1).one',2)
Invalid parameter: " /struc(1).layer(1).one"
>> setparam(tg,'/struc(1).layer(1).one',2)
Invalid parameter: "//struc"
>> setparam(tg,'/struc(1).layer(1).one','',2)
Invalid parameter: "/struc(1).layer(1).one/"
I also tried to get the parameter name from paramID and tested using another constant block in the model. I could get the information about the constant as paramID 0 but not of the structure using ID 1-5.
>> [block_path, parameter_name]=getparamname(tg,1)
Error using SimulinkRealTime.target/getparamname
speedgoat1: Invalid parameter index
>> [block_path, parameter_name]=getparamname(tg,2)
Error using SimulinkRealTime.target/getparamname
speedgoat1: Invalid parameter index
>> [block_path, parameter_name]=getparamname(tg,3)
Error using SimulinkRealTime.target/getparamname
speedgoat1: Invalid parameter index
>> [block_path, parameter_name]=getparamname(tg,4)
Error using SimulinkRealTime.target/getparamname
speedgoat1: Invalid parameter index
>> [block_path, parameter_name]=getparamname(tg,5)
Error using SimulinkRealTime.target/getparamname
speedgoat1: Invalid parameter index
Lastly here is the image of the simulink model:
Is a way to programmatically set the struc running in Simulink and target model?
Thank You

Answers (0)

Categories

Find more on Multicore Processor Targets in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!