Get correlation between segments of two matrix
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Perla González Pereyra
il 5 Ott 2019
Commentato: Perla González Pereyra
il 6 Ott 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 Commenti
Risposta accettata
the cyclist
il 6 Ott 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
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!