string variable arguments in set_param
조회 수: 2 (최근 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?
댓글 수: 0
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!