matlab报错:In an assignment A(i,j) = B,the number of columns in B and A must be the same.怎么改N=100;(100个数据)k=strcat('F:\economic\data.txt'); fid=fopen(k,'r');xt=fscanf(fid,'%f');(读成一个列向量)fclose(fid);for n=1:30Y=xt

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 16:47:32
matlab报错:In an assignment A(i,j) = B,the number of columns in B and A must be the same.怎么改N=100;(100个数据)k=strcat('F:\economic\data.txt'); fid=fopen(k,'r');xt=fscanf(fid,'%f');(读成一个列向量)fclose(fid);for n=1:30Y=xt
xTKO@+{Ayn@U^rLbSCFr yThAyT0*-п8'B됖WIKD;m]̘K'+$ڇ5S~S0ir ! HŨbiCze Iir9YX 56^,X]<3ׅ0/[z䈎uMD%S7foE}P܀%aK(`Į֜KBzbe|i< 7(noU8b[Lmgj] A0ؽi0_\|Ce8Mwts̋GM aU1z*kS?b#tUYi$R;pNnXGNnܔ*UTQ︮@zK7/)qP+]V ]5WM9BZYc&^ czP|mS5avahE2Ч{9|:Wt*2|Մ/U1[^&<8Gr[`{/t *|qeM{](eK[Kd~!.+x?6UfN2s&o$ȥE.'|tˆnr@Re _4`B?2M`Dgif/ߧH @\@dxܑil $\ܫeqx[,JY\g L ~:(m(nOAUjc/M],[v `Up=9E?Rd-Ssw=sSFfAhA {zKc

matlab报错:In an assignment A(i,j) = B,the number of columns in B and A must be the same.怎么改N=100;(100个数据)k=strcat('F:\economic\data.txt'); fid=fopen(k,'r');xt=fscanf(fid,'%f');(读成一个列向量)fclose(fid);for n=1:30Y=xt
matlab报错:In an assignment A(i,j) = B,the number of columns in B and A must be the same.怎么改
N=100;(100个数据)
k=strcat('F:\economic\data.txt');
fid=fopen(k,'r');
xt=fscanf(fid,'%f');(读成一个列向量)
fclose(fid);
for n=1:30
Y=xt;
Y(1:n)=[];
m=N-n;
X=[];
for i=1:m
for j=1:n
X(i,j)=xt(n+i-j);(取列向量中从上到下第n个数)
end
end
fai=inv(X'*X)*(X'*Y)
Delta(n)=(Y-X*fai)'*(Y-X*fai)/(N-n);
criterion(n,1)=(N+n)*Delta/(N-n);
criterion(n,2)=N*log(Delta)+2*n;
criterion(n,3)=N*log(Delta)+n*log(log(N));
end
上面字数超了,报错信息:
In an assignment A(matrix,matrix) = B,the number of columns in B and the number of elements in the A column index matrix must be the same.

matlab报错:In an assignment A(i,j) = B,the number of columns in B and A must be the same.怎么改N=100;(100个数据)k=strcat('F:\economic\data.txt'); fid=fopen(k,'r');xt=fscanf(fid,'%f');(读成一个列向量)fclose(fid);for n=1:30Y=xt
根据我的观察,问题出在当大循环泡至第圈时,即n=2时,criterion(n,1)=(N+n)*Delta/(N-n);很显然criterion(n,1)应该是一个数,而此时的Delta已经是1×2的向量,所以无法赋值,我并不懂楼主所做的问题背景,只能改成这样criterion(n,1)=(N+n)*Delta(n)/(N-n);不知合适不.
我试了一下,这样是可以的:
N=100;
% k=strcat('F:\economic\data.txt');
% fid=fopen(k,'r');
% xt=fscanf(fid,'%f');
% fclose(fid);
xt=(1:100)';
for n=1:30
Y=xt;
Y(1:n)=[];
m=N-n;
X=[];
for i=1:m
for j=1:n
X(i,j)=xt(n+i-j);
end
end
fai=inv(X'*X)*(X'*Y);
Delta(n)=(Y-X*fai)'*(Y-X*fai)/(N-n);
criterion(n,1)=(N+n)*Delta(n)/(N-n);
criterion(n,2)=N*log(Delta(n))+2*n;
criterion(n,3)=N*log(Delta(n))+n*log(log(N));
end
如果那块理解错了,请说明.