Get correlation between segments of two matrix

조회 수: 3 (최근 30일)
Perla González Pereyra
Perla González Pereyra 2019년 10월 5일
댓글: Perla González Pereyra 2019년 10월 6일
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 ?

채택된 답변

the cyclist
the cyclist 2019년 10월 6일
% 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
  댓글 수: 1
Perla González Pereyra
Perla González Pereyra 2019년 10월 6일
Thank you so much, this work pretty well.
I was thinking in create some sort of vector that goes in 25 steps, but this is more logic.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by