Extract one element from a matrix in a loop and save unto a vector
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!