Is it not possible to change the code to use block path (string such as 'myModel/Gain') instead of gcb or gcbh? This would be the most straightforward thing to try. If you cannot do this for various reasons:
How do you get the value of hBlock? If you are hard coding it as a variable (by specifying a number) there could be two issues with this:
- As this documentation says, You can use the block handle in subsequent calls to get_param or set_param. If you examine the handle, you can see that it contains a double. Do not try to use the number of a handle alone (e.g., 5.007) because you usually need to specify many more digits than MATLAB displays. Instead, assign the handle to a variable and use that variable name to specify a block. Use getSimulinkBlockHandle to get the handle to a block.
- Using hard coded values might result in breaking of logic since Simulink can change the handle to the block every time the model is loaded/opened. For e.g it could be 16.0001 now. If I close and open the model again, it maybe different.
- I am guessing the equality test might fail because you are trying to compare two floating point numbers.
For e.g. if I do this, it seems to work:
vdp
set_param('vdp/Mu','Selected','on')
hBlock = getSimulinkBlockHandle(gcb)
isequal(hBlock,gcbh)
If you run this code mutliple times (each time clearing workspace and closing the open vdp model), you can see the value of hBlock keeps changing.
Best Answer