A = A .* permute(eye(size(A, 2), [3 1 2]))
Note that it's a bit odd to stack your matrices along the first dimension. You'd be better off stacking along the third dimension which would remove the need for the squeeze in your loop, and the need for the permute in the above.
I.e. you'd be better off storing A as:
1 Comment
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/514849-convert-each-2d-matrix-in-a-collection-of-matrices-into-a-diagonal-matrix#comment_820001
Direct link to this comment
https://se.mathworks.com/matlabcentral/answers/514849-convert-each-2d-matrix-in-a-collection-of-matrices-into-a-diagonal-matrix#comment_820001
Sign in to comment.