using Corrcoef in vector

9 vues (au cours des 30 derniers jours)
Mah Mhata
Mah Mhata le 3 Juil 2019
Modifié(e) : Satwik le 23 Avr 2025
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?

Réponses (1)

Satwik
Satwik le 23 Avr 2025
Modifié(e) : Satwik le 23 Avr 2025
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!

Community Treasure Hunt

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

Start Hunting!

Translated by