How to programmaticaly set storage class (2020a) in Data Store Memory ?

6 次查看(过去 30 天)
Hi, I use Matlab 2020a.
I have hundreds of Data Store Memory Block that i generate on the Simulink model from an external file (Excel).
I've got a custom package ('mypackage') and a custom storage class within this package ('DataStore').
It works when i do it manualy.
What i want to do is setting by command line the package 'mypackage' with my storage class 'DataStore' into my data store memory block. It works when i do it manualy. To do that, i tried:
1) set(DSM_Block, 'StateSignalObject', mypackage.Signal)
--> It gives back:
"Invalid input for argument 1 (rhs1):
Value must be 'matlab.mixin.SetGet'.
Error in Simulink.DataObject/set"
2) a=get(DSM_Block_with_good_package, 'StateSignalObject')
set(DSM_Block, 'StateSignalObject', a)
--> It gives back:
"Invalid input for argument 1 (rhs1):
Value must be 'matlab.mixin.SetGet'.
Error in Simulink.DataObject/set"
And if i only write "set(DSM_Block,'StateStorageClass', 'DataStore');",
--> it gives back
"Invalid setting in DataStoreMemory block 'My_Bus' for parameter 'StateStorageClass'
Caused by:
'DataStore' is not a valid storage class"
Can you please help me ?

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2021-8-3
if "DSM_Block" is a block handle, you can use get/set
if "DSM_Block" is a block path, use set_param/get_param
  2 个评论
Jean Matthieu
Jean Matthieu 2021-8-3
That's exactly what i do, but as the question's decriptor says, it doesn't work. It specificaly does not work with 'StateSignalObject' because of the errors mentionned in the description.
Fangjun Jiang
Fangjun Jiang 2021-8-3
I tried it in R2020a. It seemed that way. It might have some dependency but hard to experiment.
I usually do it in a different way. You have hundres of DSM blocks. Each must have a unique data store name (the default is "A", for example). You need to create a signal object in base workspace or data dictionary
A=mpt.Signal and then set whatever property/value pair.
In the block, check "Data store name must resolve to Simulink signal object" option
command line is set_param(BlockPath,'StateMustResolveToSignalObject','On')
This way, the properties that you want to set are all linked to that sigal object.
This is a better way to manage the DSM blocks.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by