我有一个41x8矩阵,我想在Simulink中用它作为源码 . 源的输出应该是大小为8的行 . 数据需要在行之间进行插值 . 例如:

有一个41x1单调递增的列向量,它与第一个矩阵的41行按行对应,例如:

X=[0;        Z=[5   20;
   2.5;         10  26;
   5;           18  33;
   7.5;         27  41;
   10]          38  50]

需要在列之间进行插值(如果可能,则为三次样条插值) . 我有一个与X列向量中的值相关的输入 . 对于此示例矩阵,在X的不同值处输出simulink模型:

X=[5]        Z=[18 33]

X=[6]        Z=[25.096 39.32]

最后的Z值是从三次样条插值中获得的 .

到目前为止,我已经尝试使用Simulink中的“MATLAB函数”块和下一个代码,并使用“From workspace”块调用矩阵和向量 . 当我尝试运行模拟时,出现错误ocurr并且它表示X和Z(i)向量在函数interp1()中没有相同的尺寸

function [I] = fcn(A,X, Z)

%A: traget value for column vector
%X: 41X1 column vector
%Z: 41x8 matrix

I=zeros(1,8); %Just creating the row filled with zeros

for i=1:8
     I(i)=interp1(X,Z(:,i),A,'spline'); % Building the row interpolating at 
                                          % the A value that corresponds 
                                          % with the X1 column vector
end        

%the I column vector is an interpolated row from Z

end

有关如何使其工作的任何想法?

PD:X是和Z值必须从Matlab的基础工作区读取 .