MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Access the diagonal elements of a matrix without 'diag' function

43 correct solutions
55 incorrect solutions

Last solution submitted on May 17, 2015

1 Comment

Khaled Hamed
on 30 Dec 2012

Right solution to right problem

1 Comment

Duane Hanselman
on 30 Dec 2012

Test #5 is incorrect. Transpose on x makes the diagonal [1 5 9], [1 6 11] are not on any diagonal. #5 is the transpose of #4 and taking the transpose does not change the diagonal, unless you have some other definition for diagonal. A good solution is x(find(eye(size(x))))

1 Comment

Khaled Hamed
on 30 Dec 2012

Rigt solution for wrong problem

1 Comment