Extract one element from a matrix in a loop and save unto a vector
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi there,
I'm trying to store the correlation coefficients between one variable and 6 (respectively) leads and lags of another variable. I'm aware there's ways to go around negative indexing-have seen there's a few questions and answers on that. I'm struggling with something even more basic, though.
I pre-allocate a vector where I want to store results (corcoefvector), but then what I have in the loop doesn't work, because the RHS returns a 2x2 matrix (the matrix of correlation coefficients), and what I need is to extract only one element, that is, one of the off-diagonal values (since it's just two variable at each iteration of the loop), say element (1,2) from the matrix of coefficient at iteration 1 and shove it in position (1,1) of corcoefvector, and keep doing this as j goes from 1 to 6. The size of the LHS is 1-by-1, the size of the RHS is 2-by-2. I'm at a loss as to the best way to proceed. Would highly appreciate some help in getting unstuck
corcoefvector=zeros(1,6);
for j=1:6
corcoefvector(1,j)= corrcoef(filteredcol2,lagmatrix(filteredcol1,j),'rows','complete');
end
Many thanks
3 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical 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!