Code to assign correlation values from a correlation matrix to a column vector
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to create a loop that repeats (iters) times which creates 2 random vectors (v1 and v2) using randn of size (sz) and finds the correlation between those two vectors, and I have to assign the correlation values to a column vector (cors) and plot the histogram of (cors).
My problem is i dont know how to assign correlation values to a column vector. Can anyone help?

0 commentaires
Réponses (1)
Turlough Hughes
le 21 Avr 2023
You're almost there - use the loop variable, ii, to index into cors as follows:
sz = 1000;
iters = 10000;
cors = zeros(iters,1);
for ii = 1:iters
v1 = randn(sz,1);
v2 = randn(sz,1);
x = corrcoef([v1,v2]);
cors(ii,1) = x(1,2); % <- here
end
histogram(cors,120)
0 commentaires
Voir également
Catégories
En savoir plus sur Histograms dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!