string variable arguments in set_param

3 visualizaciones (últimos 30 días)
Alexander Van Waeyenberge
Alexander Van Waeyenberge el 24 de Mayo de 2021
Editada: Fangjun Jiang el 24 de Mayo de 2021
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?

Respuestas (1)

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

Categorías

Más información sobre Programmatic Model Editing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by