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/05/10 17:58:19
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: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
如果那块理解错了,请说明.