I'm getting error message 'In an assignment A(I) = B, the number of elements in B and I must be the same, Error in BM3D (line 25) Y(i+1)=Y(i​)*(1-k/(6*​pi))+sqrt(​12*pi/delt​at)*m1*del​tat/(6*pi)​; '... Can someone please help me to correct my mist

2 次查看(过去 30 天)
clear all
clc
k=1;
deltat=1;%time interval
tmax=200;
N=input('enter the no of iteations required = ')
X=zeros(1,2*(tmax+2));%initaial position set to 0
Y=zeros(1,2*(tmax+2));%initaial position set to 0
Z=zeros(1,2*(tmax+2));%initaial position set to 0
for K=1:N
for i=1:2:tmax
x1=rand(1);
x2=rand(1);
y1=rand(1);
y2=rand(2);
z1=rand(1);
z2=rand(2);
n1=((sqrt(-2*log(x1)))*(cos(2*pi*x2)));
n2=((sqrt(-2*log(x1)))*(sin(2*pi*x2)));
X(i+1)=X(i)*(1-k/(6*pi))+sqrt(12*pi/deltat)*n1*deltat/(6*pi);
X(i+2)= X(i+1)*(1-(k/(6*pi)))+sqrt(12*pi/deltat)*n2*deltat/(6*pi);
m1=((sqrt(-2*log(y1)))*(cos(2*pi*y2)));
m2=((sqrt(-2*log(y1)))*(sin(2*pi*y2)));
Y(i+1)=Y(i)*(1-k/(6*pi))+sqrt(12*pi/deltat)*m1*deltat/(6*pi);
Y(i+2)= Y(i+1)*(1-(k/(6*pi)))+sqrt(12*pi/deltat)*m2*deltat/(6*pi);
l1=((sqrt(-2*log(z1)))*(cos(2*pi*z2)));
l2=((sqrt(-2*log(z1)))*(sin(2*pi*z2)));
Z(i+1)=Z(i)*(1-k/(6*pi))+sqrt(12*pi/deltat)*l1*deltat/(6*pi);
Z(i+2)= Z(i+1)*(1-(k/(6*pi)))+sqrt(12*pi/deltat)*l2*deltat/(6*pi);
end
s=zeros(1,tmax+1);
for i=1:tmax+1
s(1)=0;sy(1)=0;sz(1)=0;
for j=2:tmax+2
s(i)=s(i)+X(j)*X(j+i);
sy(i)=sy(j)+Y(j)*Y(j+1);
sz(i)=sz(k)+Z(j)*Y(j+1);
end
end
for i=1:tmax
avx(K,i)=s(i)/tmax;
avy(K,i)=sy(i)/tmax;
avz(K,i)=sz(i)/tmax;
end
end
for n=2:tmax
M1(n)=mean(avx(:,n));
M2(n)=mean(avy(:,n));
M3(n)=mean(avz(:,n));
end
hold on
xlabel('time(t)')
ylabel('<x(t)x(0)>')
title('Autocorrelation')
x =2:tmax;
y=exp(-x/(6*pi));
plot(x,y,'LineWidth',4)
plot(x,M1(x),'g')
plot(x,M2(x),'r')
plot(x,M3(x),'k')
  1 个评论
Matthew Eicholtz
Matthew Eicholtz 2013-6-27
编辑:Matthew Eicholtz 2013-6-27
I would suggest trying to pose your question and description in a more pleasing way to readers. Cut-and-pasted error messages in the title makes it difficult for people to help you.

请先登录,再进行评论。

回答(2 个)

Matt J
Matt J 2013-6-27
编辑:Matt J 2013-6-27
In
Y(i+1)=Y(i)*(1-k/(6*pi))+sqrt(12*pi/deltat)*m1*deltat/(6*pi);
The left hand side is a scalar location but the right hand side is a 2x2 matrix, because m1 is a 2x2 matrix. You cannot park a 2x2 car in a 1x1 parking space.

Matthew Eicholtz
Matthew Eicholtz 2013-6-27
  • Your current error is due to the fact that your code attempts to assign a 2x2 array to a single element in the vector Y.
  • The reason the right side of the equation in line 25 is a 2x2 array is because of m1.
  • m1 is a 2x2 array because of y2
  • If you change line 16 and line 18 to rand(1) instead of rand(2), this fixes your current error. However, when I run the code again, a new error appears elsewhere.
You should clarify what you are trying to do.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by