In my Simulink diagram, I have a const block that references a global variable (lets call it myVar). I have an event handler that is called every clock tick (looks for a change in a clock block's output). That handler looks like this:
function speedRampUpUTManager(block, eventdata) simTime = block.OutputPort(1).Data; global myVar; if(simTime == 10) myVar = 1500; //myVar is initialized to 1700 end disp('myVar:'); disp(myVar); end
Sure enough, during a simulation the disp shows 1700, then starts showing 1500. However, when I look at the scope attached to the const block with the Simulation Data Inspector, the value is 1700 the whole time.
My const block has the following settings:
- Const Value: myVar
- Interpret vector parameters as 1-D: unchecked
- Sampling mode: Sample Based
- Sample Time: -1
Perhaps one workaround might be:
set_param(constBlock, 'Value', 'myVar')
But I'd like to avoid that if possible.
Regards, Istvan.
Best Answer