I want to simplify my code, because it is very time consuming. In my problem, R is a bout 4000, so corr function should be call for more than 16000000 times. haw can I simplify this code?
for i=1:R
for j=1:R
Red1 = Red1 + abs(corr (SelectedData,i,j));
end
end
edit: So, I should say that, corr function is written by me and it compute correlation between two features.
and this is my corr function:
function corr = corr (X, i, j)
covariance = (cov((X(:,i)),(X(:,j))));
corr = (covariance(1,2))/((sqrt(var(X(:,i)))) * (sqrt(var(X(:,j)))) );
end
correlationfunction in the wrong way: it must contain 4 arguments (5th is not necessary). Look at this documentation. And the second:correlationcannot works foriandjof array type, so I think we can avoid loop using somearrayfunorbsxfunbut we still have to usecorrelationfor 16m times (4000*4000)... But I'm not sure here :)corris built in function too: MATLAB doc :D Ok, now let's try to workaround for you function...