I have the following code that includes 3 iterated for loops in order to create an upper diagonal matrix, I plan on performing on large data set many times and want to make as computationally efficient as possible.
data = magic(3);n = size(data,1);W = zeros(n,n);for i = 1:n for j = i:n if i==j www(i,j)=0; else for k = 1:n temp(1,k) = (data(i,k)-data(j,k))^2; sumTemp = sumTemp + temp(1,k); end W(i,j)=sqrt(sumTemp); end temp = 0; sumTemp = 0; endend
Answer should look like:
[0 6.4807 9.79800 0 6.48070 0 0]
I am working it hard right now, but figure I would throw it out there in case anyone has any suggestions that would save me hours of fiddling around. Thanks in advance.
Keith
Best Answer