我的matlab功能代码中出现以下错误:
???下标索引必须是实数正整数或逻辑。
==>中的错误AFA 15岁 M(k,j)= mean(T(i:sze,j));
这是问题所在代码的一部分:
sz =size(T);
lim = sz(2) - ordre;
M = zeros(sz(1),sz(2));
r= 0;
for j=1:sze,
k = 1;
for i=1:lim,
M(k,j) = mean(T(i:i+ordre,j));
k = k + 1;
end
for i=lim+1:sz(2),
M(k,j) = mean(T(i:sz(2),j));
k = k + 1;
end
end
答案 0 :(得分:0)
以下适用于我而没有错误
T = magic(25);ordre = 5; %# I make up some values here
sz =size(T);
lim = sz(2) - ordre;
%# I've added a check here
if lim < 1, error('ordre has to be at most sz(2)-1 (is %i)',ordre);end
M = zeros(sz(1),sz(2));
r= 0;
for j=1:sz(2), %# I needed to change this line (sz(1) works as well)
k = 1;
for i=1:lim,
M(k,j) = mean(T(i:i+ordre,j));
k = k + 1;
end
for i=lim+1:sz(2),
M(k,j) = mean(T(i:sz(2),j));
k = k + 1;
end
端