selection of one parameter for correlation coefficient
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuestas (1)
Abhishek Chakram
el 22 de Sept. de 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
0 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!