To find the correlations of the variables in a matrix in Matlab, you can use the corrcoef
function.
main.m218 chars13 lines
In this example, we have a 5x5 matrix with 5 variables. The corrcoef
function calculates the correlation coefficients between all pairs of variables and returns a new 5x5 matrix of correlation coefficients. The diagonal of the matrix contains the correlation coefficients between each variable with itself, which are all 1.
You can also use the corr
function to calculate the pairwise correlation coefficients between columns of a matrix and display a correlation matrix as a heatmap.
main.m268 chars15 lines
This code will produce a heatmap of the correlation matrix C
, where higher correlation coefficients are displayed in brighter colors. The corr
function also calculates p-values for each correlation coefficient, which can be used to test for statistical significance of the correlations.
gistlibby LogSnag