Azzera filtri
Azzera filtri

Code to assign correlation values from a correlation matrix to a column vector

1 visualizzazione (ultimi 30 giorni)
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?

Risposte (1)

Turlough Hughes
Turlough Hughes il 21 Apr 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)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by