string variable arguments in set_param

3 次查看(过去 30 天)
Hi there!
I'm trying to automate the commenting of blocks in a simulink model I'm using for my thesis.
Everything works so far, except finding a way to fill in the last argument of the first "set_param()" function. This should either be "on" or "off", depending on if I want the Simulink block to be commented out or not. I replaced this with "p1x2(1,i)" which is an array with "on"s and "off"s in the cells, basicly derived from the matrix M1x2 with on the second row '1's and '0's, where 1 means the block "CB1x2" shouldn't be commented out, while 0 means the block should be commented out.
CB1x2 = getSimulinkBlockHandle('thesis/CB1x2');
onOffTable = {'on', 'off'};
p1x2 = num2cell(M1x2(2,:));
p1x2 = onOffTable((M1x2(2,:)) +1);
Here is the problem though: for some reason the set_param doesn't take variable arguments in a string form.
set_param(CB1x2,'Commented',p1x2(1,1));
set_param('thesis','SimulationCommand','Update')
I used disp(p1x2(1,1)); and this gave back {'off'}, so there shouldn't be anything wrong with the imput.
I keep getting this error though:
Error using BusConnectionSwitchScript (line 232)
Invalid setting in block 'CB1x2' for parameter 'Commented'
Can someone spot the obvious mistake I made? Maybe in the syntax?
Or is it just not possible to feed variables into the set_param function?

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2021-5-24
编辑:Fangjun Jiang 2021-5-24
p1x2(1,1) is cell, use p1x2{1,1}
or define onOffTable = ["on","off"] if your MATLAB version support string data type

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by