Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

MATLAB error 'index exceeds matrix dimensions'

1 visualización (últimos 30 días)
ali
ali el 4 de Feb. de 2016
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
hello all
i want to run this function but i got index exceeds, i checked my loops but i could not saw the error.
where vn=vs=1 and M=100 and th1=1000 and Dr1=D1=0
function D=distortion(vn,vs,M,th1,x,y,Dr1,D1);
for i=1:M;
for j=1:M;
if i~=j
d1(i,j)=sqrt(((y(j)-y(i))^2+(x(j)-x(i))^2));
Dr1=exp(-d1(i,j)/th1)+Dr1;
end
end
end
for i=1:M
ds1(i)=sqrt(((y(j)-0)^2+(x(j)-0)^2));% point source at 0 0
cor2=exp(-ds1(i)/th1);
D1=cor2+D1;
end
D=(vs^2)-((vs^4)/(M*((vs^2)+(vn^2))))*(2*(D1-1))+((vs^6)/((M^2)*((vs^2)+(vn^2)))*Dr1);
end

Respuestas (1)

Image Analyst
Image Analyst el 4 de Feb. de 2016
This worked for me.
function test1
vn=1
vs=1 ;
M=100 ;
th1=1000;
Dr1=0;
D1=0
y = rand(1,M);
x = rand(1,M);
D=distortion(vn,vs,M,th1,x,y,Dr1,D1)
end
function D=distortion(vn,vs,M,th1,x,y,Dr1,D1)
for i=1:M;
for j=1:M;
if i~=j
d1(i,j)=sqrt(((y(j)-y(i))^2+(x(j)-x(i))^2));
Dr1=exp(-d1(i,j)/th1)+Dr1;
end
end
end
for i=1:M
ds1(i)=sqrt(((y(j)-0)^2+(x(j)-0)^2));% point source at 0 0
cor2=exp(-ds1(i)/th1);
D1=cor2+D1;
end
D=(vs^2)-((vs^4)/(M*((vs^2)+(vn^2))))*(2*(D1-1))+((vs^6)/((M^2)*((vs^2)+(vn^2)))*Dr1);
end
What did you pass in for X and Y?
  16 comentarios
Walter Roberson
Walter Roberson el 5 de Feb. de 2016
You see the importance of showing us the actual error instead of just saying that you get an error somewhere?
ali
ali el 5 de Feb. de 2016
yes u r right

La pregunta está cerrada.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by