Get correlation between segments of two matrix

3 ビュー (過去 30 日間)
Perla González Pereyra
Perla González Pereyra 2019 年 10 月 5 日
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