matlab中?Subscripted assignment dimension mismatch.X0=[1 4 7]X1=cumsum(X0)%累加w=[0.5 0.4 0.3]m=length(w)n=length(X1) B=zeros(2,6)for i=1:mfor j=1:n-1X2(j,i)=w(i)*X1(j)+(1-w(i))*X1(j+1) endt=ones(n-1,3)B(:,2*i-1:2*i)=[-1.*X2(:,i),t(:,i)]endYN=X0(2
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/25 17:38:24
matlab中?Subscripted assignment dimension mismatch.X0=[1 4 7]X1=cumsum(X0)%累加w=[0.5 0.4 0.3]m=length(w)n=length(X1) B=zeros(2,6)for i=1:mfor j=1:n-1X2(j,i)=w(i)*X1(j)+(1-w(i))*X1(j+1) endt=ones(n-1,3)B(:,2*i-1:2*i)=[-1.*X2(:,i),t(:,i)]endYN=X0(2
matlab中?Subscripted assignment dimension mismatch.
X0=[1 4 7]
X1=cumsum(X0)%累加
w=[0.5 0.4 0.3]
m=length(w)
n=length(X1)
B=zeros(2,6)
for i=1:m
for j=1:n-1
X2(j,i)=w(i)*X1(j)+(1-w(i))*X1(j+1)
end
t=ones(n-1,3)
B(:,2*i-1:2*i)=[-1.*X2(:,i),t(:,i)]
end
YN=X0(2:end)
P_t=YN./X1(1:(length(X0)-1)) %对原始数据序列X0进行准光滑性检验,
%序列x0的光滑比P(t)=X0(t)/X1(t-1)
A=zeros(2,3)
a=zeros(1,3)
u=zeros(1,3)
for l=1:3
A(:,l)=inv(B(:,2*l-1:2*l).'*B(:,2*l-1:2*l))*B(:,2*l-1:2*l).'*YN.'
a(l)=A(1,l)
u(l)=A(2,l)
end
c=u./a
b=repmat(X0(1),1,3)-c
Y_k_1=zeros(3,3)
for t=1:length(X0)
k(1,t)=t-1
end
k
for p=1:3
for q=1:3
Y_k_1(p,q)=b*exp(-a(p)*k(q))+c
end
end
Subscripted assignment dimension mismatch.
问题出在最后一行代码上,
matlab中?Subscripted assignment dimension mismatch.X0=[1 4 7]X1=cumsum(X0)%累加w=[0.5 0.4 0.3]m=length(w)n=length(X1) B=zeros(2,6)for i=1:mfor j=1:n-1X2(j,i)=w(i)*X1(j)+(1-w(i))*X1(j+1) endt=ones(n-1,3)B(:,2*i-1:2*i)=[-1.*X2(:,i),t(:,i)]endYN=X0(2
Y_k_1(p,q)=b*exp(-a(p)*k(q))+c
这里面的c是一个数组,一个数和一个数组相加赋值给一个数,那是不对的!
Subscripted assignment dimension mismatch.
这个就是下标不匹配!