Get correlation between segments of two matrix
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!