Igor Frassoni
Igor Frassoni

Reputation: 15

How to vary the array elements of this matrix

Ok, i've the following FOR structure:

Ny = 246;
Nx = 190;


for n1y = 1:Ny
 for n1x = 1:Nx

  for n2y = 1:Ny
   for n2x = 1:Nx

   n1 = 
   n2 = 

   dx12 = xax(n1x) - xax(n2x);  
   dy12 = xay(n1y) - xay(n2y);
    r12 = sqrt(dx12^2+dy12^2); 

    B(n1,n2) = 0.8 * exp((-1/2)*(r12/300));

   end
  end

 end
end  

Where, xax is a vector of length 190 and xay is a vector of length 246.

My doubt is, how can i determine n1 and n2 in the way that B becomes a (Nx*Ny , Nx*Ny) matrix?

Ps.: sorry for the language errors, my native language is not English.

Thanks.

Upvotes: 1

Views: 30

Answers (1)

Bas Swinckels
Bas Swinckels

Reputation: 18488

Probably something like

n1 = (n1x - 1) * Ny + n1y;
n2 = (n2x - 1) * Ny + n2y;

or the same with all the x and y parts swapped.

But it seems that you are constructing a gigantic matrix B of size (246*190)^2*8 / 1e9 = 17 gigabyte! Is that really what you want?

Upvotes: 1

Related Questions