矩阵每一行运算用for循环怎么不报错不出结果?[m1,n1]=size(f2);for i=1:n1y=f2(i,:);if(size(y,2) > 1) y=y'; endm=1;n = length(y);rho = zeros(m,1);npm = n+m;tmp = std(y);vary=tmp.*tmp;% put y in deviations from mean formym = mean(y);e =
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/25 19:25:38
矩阵每一行运算用for循环怎么不报错不出结果?[m1,n1]=size(f2);for i=1:n1y=f2(i,:);if(size(y,2) > 1) y=y'; endm=1;n = length(y);rho = zeros(m,1);npm = n+m;tmp = std(y);vary=tmp.*tmp;% put y in deviations from mean formym = mean(y);e =
矩阵每一行运算用for循环怎么不报错不出结果?
[m1,n1]=size(f2);
for i=1:n1
y=f2(i,:);
if(size(y,2) > 1)
y=y'; end
m=1;
n = length(y);
rho = zeros(m,1);
npm = n+m;
tmp = std(y);
vary=tmp.*tmp;
% put y in deviations from mean form
ym = mean(y);
e = zeros(n,1);
e(1:n,1) = y-ones(n,1)*ym;
bigY=repmat([1:n]',2*(m+1),1);
bigY=bigY(1:(2*n-1)*(m+1));
bigY=reshape(bigY,2*n-1,m+1);
bigY=bigY(1:n,2:m+1);
bigY=y(bigY);
E=repmat(e,1,m);
rho=(sum(E.*bigY)/(n*vary))';
ul = 2*(1/sqrt(n)*ones(m,1));
ll = -2*(1/sqrt(n)*ones(m,1));
bar(rho,1);
title('Sample autocorrelation coefficients');
xlabel('lags');
ylabel('sacf');
hold on;
tt=1:m;
plot(tt,ul,'*r',tt,ll,'*r');
hold off;
i=i+1;
end
矩阵每一行运算用for循环怎么不报错不出结果?[m1,n1]=size(f2);for i=1:n1y=f2(i,:);if(size(y,2) > 1) y=y'; endm=1;n = length(y);rho = zeros(m,1);npm = n+m;tmp = std(y);vary=tmp.*tmp;% put y in deviations from mean formym = mean(y);e =
用 f2=rand(10,10) 测试,程序运行良好.不知道你的为什么不出结果.
不过,你这程序,本身有些小问题:
---------------------------------------------
[m1,n1]=size(f2); %行m1,列n1
for i=1:n1 %按你说的不是应该按行循环:for =1:m1 么?
---------------------------------------------
最好先说明下你想干什么,然后各行程序能注释的就注释一下,比如bigY那一段——方便他人快速的理解你的程序并找出可能的原因.