我不断收到此错误:
索引表达式超出范围。 尝试访问元素2。有效范围是1-1。“ 2”。
我想要的输出是
abs(I(2,ii(a))-I(2,ii(a)-1)
所以当ii(a)=2 ,我希望I(2,2)减去I(2,1) ,即5.1减去5.0
该错误归因于此行:
arr(1,ii(a)) = arr(1,ii(a)) + abs(I(2,ii(a))-I(2,ii(a)-1));.
我在.mat文件中将我定义如下:
save data -v7.3 'I'
load('data.mat','I');
I =
Columns 1 through 6
0 1.0000 2.0000 3.0000 4.0000
5.0000 5.1000 5.2000 5.2000 5.5000
编码:
function arr= fcn(I,count,oldval)
persistent integ_signal
if isempty( integ_signal)
integ_signal=zeros(1,5)
end
persistent a
if isempty(a)
a=zeros(1)
end
arr=zeros(1,5);
ii=zeros(1,5);
aa=zeros(2,5);
integ_signal=oldval;
coder.extrinsic('load');
aa=load('data.mat','I');
if count==1
a=1;
ii(a)=count;
integ_signal(1,ii(a)) = 10; % Initial Condition
end
if count ~= 1
a=count;
ii(a)=count;
integ_signal(1,ii(a))= integ_signal(1, ii(a)-1);
arr(1,ii(a)) = integ_signal(1,ii(a));
arr(1,ii(a)) = arr(1,ii(a)) + abs(aa(2,ii(a))-aa(2,ii(a)-1));
end
a = a + 1;
end