MATLAB: Parameters from MATLAB function in Simulink

simulink block parameter

Hi
I'm writing a function in MATLAB. In this function I call a Simulink diagram with following command: sim('diagram', 'vxin', value) The error I get is: block_diagram does not have a parameter named 'vxin'. In the diagram I have a constant block where I entered vxin. Clearly this isn't the right way.
How can I fix this?
Thanks

Best Answer

It depends on how you want to manage the scope of vxin .
Simple option:
vxin=value;
sim('diagram');
or maybe you want something like:
h=get_param('diagram','modelworkspace');
h.assignin('vxin',value);
sim('diagram');
Related Question