|
I would like to share array in Simulink matlab function blocks. I used the Simulink.Signal object to share the array in several matlab function blocks but my array increment with time. How can I set the array to constant, which does not change with simulation time.
Below is what I did.
1)Initialize variable in matlab workspace
a=Simulink.Signal;
a.DataType = 'double';
a.Complexity = 'real';
a.Dimensions = [2 2];
a.SamplingMode='Sample based';
a.SampleTime = -1;
a.InitialValue='ones(2,2)';
2)My simulink model only consist of 2 blocks, which are matlab function block and display.
Also, array "a" is included in ports and data manager. My matlab function blocks is below.
function y=fcn
global a
a=a+1;
y=a;
When I run this simulation, I expect to see [2 2;2 2] on the display block but it is not the case. The value in the display block increments with time.
How should I change my code to do exactly what I want it to do?
Thanks!
|