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

조회 수: 6 (최근 30일)
Paulos
Paulos 2023년 4월 21일
답변: Turlough Hughes 2023년 4월 21일
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?

답변 (1개)

Turlough Hughes
Turlough Hughes 2023년 4월 21일
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)

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by