Filter löschen
Filter löschen

selection of one parameter for correlation coefficient

3 Ansichten (letzte 30 Tage)
Ismita
Ismita am 29 Apr. 2022
Beantwortet: Abhishek Chakram am 22 Sep. 2023
Suppose, I have 100 rows of P and Q, and 20 rows of data make a group. Average of each group gives new set of data points (total 5 for each). I want to calculate correlation of coefficient for each group. But it gives 2x2 matrics. how can I select one value for each data 20 row?
P = [1:100];
Q = [1:100];
index = 20;
new_group = zeros(5,3); % average of each 20 row of P (=P_av), Q (=Q_av), and correlation of coefficient for each 5 groups of P and Q
A = randn(10,1);
B = randn(10,1);
R = corrcoef(A,B)
Result: R = 2×2
1.0000 0.4518
0.4518 1.0000 %
%how to select one (here 0.4518) for each group?
Thanks a lot in advance.

Antworten (1)

Abhishek Chakram
Abhishek Chakram am 22 Sep. 2023
Hi Mst Ismita Tasnim,
It is my understanding that you are facing difficulty in writing the code for selecting a particular parameter for correlation coefficient. Here’s an example for the same:
P = [1:100];
Q = [1:100];
index = 20;
new_group = zeros(5,3); % average of each 20 row of P,Q,and the correlation coefficient for each 5 groups of P and Q
% Loop through each group
for i = 1:5
% Select the rows for the current group
start_index = (i-1)*index + 1;
end_index = i*index;
P_group = P(start_index:end_index);
Q_group = Q(start_index:end_index);
% Calculate the average of P and Q for the current group
P_av = mean(P_group);
Q_av = mean(Q_group);
% Calculate the correlation coefficient for the current group
R = corrcoef(P_group, Q_group);
correlation_coefficient = R(1, 2); % Select the value at (1, 2) position
% Store the results in the new_group array
new_group(i, :) = [P_av, Q_av, correlation_coefficient];
end
Best Regards,
Abhishek Chakram

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by