Get correlation between segments of two matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Perla González Pereyra
el 5 de Oct. de 2019
Comentada: Perla González Pereyra
el 6 de Oct. de 2019
I have two matrix (matrix1=2325x25 and matrix2=2175x25), I want to calculate the correlation between matrix1([1:25],:) and matrix2([1:25],:) and successively matrix1([1:25],:) and matrix2([25:51],:)until i get all posible combinationd between segments;like there were independent segments of 25x25 and i wanted to compared each posible pair.
Any idea how can i do it ?
0 comentarios
Respuesta aceptada
the cyclist
el 6 de Oct. de 2019
% Some made-up data
matrix1 = randn(2325,25);
matrix2 = randn(2175,25);
% Define the segment size, for generality
segment = 25;
% The number of segments in each matrix
numSeg1 = size(matrix1,1)/segment;
numSeg2 = size(matrix2,1)/segment;
% Preallocate the matrix that will store the correlation between all
% segments
segmentCorrelations = zeros(numSeg1,numSeg2);
% Loop over all pairs of segments
for i1 = 1:numSeg1
for i2 = 1:numSeg2
% Get the indices for the elements of this pair of segments
index1 = segment*(i1-1) + 1 : segment*i1; % This line can be pulled out of the inner loop
index2 = segment*(i2-1) + 1 : segment*i2;
% Calculate the correlation matrix between these two segments
tempCorr = corrcoef(matrix1(index1,:),matrix2(index2,:));
% Store the correlation coefficient (which is the upper right of the matrix, or equivalently lower left)
segmentCorrelations(i1,i2) = tempCorr(1,2);
end
end
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!