如何在simulink中用data store传递数组

用simulink搭建一个数据采集模型,子程序数据采集主程序进行传输,子程序采集的数据保存在一个数组中想用全局变量的方法在主程序中调用数组。用了data store定义全局变量,并且在data store memory里初始化用zero函数初始化了一个数组,但结果显示数组里所有的数都为同一个值

对于模型进行了简化,主要是定义全局向量的问题

img

左侧程序为
function fcn()
%#codegen
global U1;
persistent i;

if isempty(i)
i=1;
U1=double(zeros(1000,1));

end
if i<=1000
U1(i,1)=i;
end

i=i+1;

end
右侧程序
function u1=fcn
%#codegen
global U1;
persistent i;

if isempty(i)
i=1;

end
u1=1;
if i>100&&i<=1100
u1=double(U1(i-100,1));
end

i=i+1;

end
data store memory设定

img

结果示波器输出为1

模型发出来看一下吧,光说也不知道是什么原因。

初始化已经赋值了,后面再次赋值才会改变。
用法按文档操作,不会错的。
https://blog.csdn.net/Lookerkid/article/details/117533321