using Corrcoef in vector

조회 수: 9 (최근 30일)
Mah Mhata
Mah Mhata 2019년 7월 3일
편집: Satwik 2025년 4월 23일
I have 2 vector which sizes are 1*100 .
I want to compute correlation between all vector elements, but as you know corrcoef just show 2*2 matrix. not for all of the number, whoat should I do?

답변 (1개)

Satwik
Satwik 2025년 4월 23일
편집: Satwik 2025년 4월 23일
If two vectors of size 1×100 are given, the correlation between corresponding elements is computed as a single correlation coefficient. The 'corrcoef' function returns a 2×2 matrix, where the off-diagonal element is the correlation value between the two vectors. To compute the correlation between all pairs of elements (i.e., a 100×100 matrix), a correlation matrix can be formed by combining the vectors into a 100×2 matrix, and then the correlations between all columns can be computed.
A = rand(1,100);
B = rand(1,100);
% Pairwise correlation matrix (each element: correlation between scalar pairs)
corrMat = (A' - mean(A)) * (B - mean(B)) / ((length(A)-1) * std(A) * std(B));
However, this will produce a matrix where each entry is the product of deviations, not standard correlation.
Kindly refer to the following documentation for detailed information on the 'corrcoef' function: https://www.mathworks.com/help/matlab/ref/corrcoef.html
I hope this helps!

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by