How to create a 2D diagonal matrix from a 3D matrix with a generic dimension? It could be with a loop structure.
Mostra commenti meno recenti
%%3D matrix k
n=3;
k=zeros(n)
for a=1:n
for b=1:n
for c=1:n
k(b,c,a)=c;
end
end
end
using blkdiag could be obtained, however for a generic number of matrices n, this doesn't work.
u=blkdiag(k(:,:,1),k(:,:,2),k(:,:,3))
1 Commento
Stephen23
il 16 Nov 2017
What is the expected output? Can you please provide a specific example with input and output arrays.
Risposta accettata
Più risposte (1)
Matt J
il 16 Nov 2017
kcell=num2cell(k,[1,2]);
u=blkdiag(kcell{:});
Categorie
Scopri di più su Operating on Diagonal Matrices in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!