%% Test Banded Matrix
% Create a matrix with nonzero elements on the main and first diagonals.

A = 3*eye(4) + diag([2 2 2],1)

%
% Test to see if the matrix is diagonal.

isdiag(A)

% The matrix is not diagonal since there are nonzero elements above the main diagonal.
%
% Create a new matrix, B, from the main diagonal elements of A.

B = diag(diag(A));

%
% Test to see if B is a diagonal matrix.

isdiag(B)

% The result is logical 1 (true) because there are no nonzero elements above or below the main diagonal of B.
% Copyright 2012 The MathWorks, Inc.