Hello,
I have been thinking on vectorizing this code:
mat=zeros(a^2,a^2);x=[1:a];y=[1:a];[Xm,Ym]=meshgrid(x,y)for i=1:a^2 for j=1:a^2 [x1,y1]=ind2sub([a a],i); [x2,y2]=ind2sub([a a],j); mat(i,j)=(Xm(x1,y1)-Xm(x2,y2))^2+(Ym(x1,y1)-Ym(x2,y2))^2); endend
This takes too long as
a^2 is about 20k.
I still haven't been able to come with a nice solution, and not sure if it's even possible. If anyone can give me a hand I really appreciate it.
Thank you in advance.
Best Answer