# Create a single variable to store multiple correlation coefficients

5 Ansichten (letzte 30 Tage)
Rivers Cuomo am 30 Mär. 2023
Beantwortet: John D'Errico am 30 Mär. 2023
I have a 300x7 matrix (A) and a 1x300 row vector (B). How do I calculate the CC for each of the 7 columns in A against the single row in B and store them in a single variable?
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (2)

John D'Errico am 30 Mär. 2023
A = rand(300,7);
B = rand(1,300);
C = corrcoef([A,B']);
C = C(8,1:7)
C = 1×7
0.0055 -0.0433 0.0186 -0.0125 0.0854 0.0879 -0.1811
The correlation coefficiens of each column of A, against B are given in C; Admittedly, if the array A had many columns, then the above is wasteful in terms of CPU cycles. So I could also have done this:
C2 = (B-mean(B))/norm(B-mean(B))*normalize(A - mean(A),1,'norm')
C2 = 1×7
0.0055 -0.0433 0.0186 -0.0125 0.0854 0.0879 -0.1811
As you can see, the results are the same.
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

Luca Ferro am 30 Mär. 2023
Bearbeitet: Luca Ferro am 30 Mär. 2023
this would do the trick and store the correlation values in a 300x7 matrix
for rr=1:size(AA,1)
for cc=1:size(AA,2)
CC(rr,cc)=corrcoef(A(rr,cc),B(1,rr));
end
end
The order of the matrix follows the order of A, meaning that CC(1,1) is the correlation of A(1,1) and B(1), and so on
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on Correlation and Convolution in Help Center and File Exchange

R2023a

### Community Treasure Hunt

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

Start Hunting!

Translated by