extracting diagonals from 3d matrices

I try to extract diagonals from 7*7*217 matrices into 1*7*217. How can i make it? I tried below code but it did't work. I would appreciate if you help me.
for k=1:217
D(:,:,k)=diag(diag(L(:,:,k)));
end

Réponses (1)

Matt J
Matt J le 4 Mar 2018
Modifié(e) : Matt J le 4 Mar 2018
Lr=reshape(L,1,49,[]);
D=Lr(1,1:8:end,:);

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by