How can I vectorize these nested for-loops in Matlab?
I have a piece of code here I need to streamline as it is greatly
increasing the runtime of my script:
size=300;
resultLength = (size+1)^3;
freqResult=zeros(1, resultLength);
inc=1;
for i=0:size,
for j=0:size,
for k=0:size,
freqResult(inc)=(c/2)*sqrt((i/L)^2+(j/W)^2+(k/H)^2);
inc=inc+1;
end
end
end
c, L, W, and H are all constants. As the size input gets over about 400,
the runtime is too long to wait for, and I can watch my disk space
draining by the gigabyte. Any advice?
Thanks!
No comments:
Post a Comment