For loop for correlation
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a large dataset (9x6925) where I need to find the corrcoef, keeping one column constant and testing it with the other columns. How can I do that using for loop.
0 comentarios
Respuestas (1)
Jos (10584)
el 17 de Dic. de 2013
Here is a method:
% create some data
A = 10*rand(10,4) ;
k0 = 1 ; % reference column
% add some columns for demo purposes
A(:,end+1) = 2*A(:,k0) ; % perfect correlation with
A(:,end+1) = 3*A(:,k0) + 2*rand(10,1) ; % some correlation
% find the correlations among columns
N = size(A,2) ;
CC = zeros(1,N) ; % pre-allocation to store the coefficients
for k = 1:N,% loop over all columns
tmp = corrcoef(A(:,k0),A(:,k)) ;
CC(k) = tmp(1,2) ;
end
disp(CC)
Note that CC(k0) is 1, per definition
You could also use corrcoef to get all correlations and select the ones you want
tmp = corrcoef(A) % A N-by-N array
CC = tmp(k0,:)
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!