%% Find Bandwidth of Triangular Matrix
% Create a 6-by-6 lower triangular matrix.

A = tril(magic(6))

%
% Find the lower bandwidth of A by specifying type as 'lower'. The result is 5 since every diagonal below the main diagonal has nonzero elements.

B = bandwidth(A,'lower')

%
% Find the upper bandwidth of A by specifying type as 'upper'. The result is 0 since there are no nonzero elements above the main diagonal.

B = bandwidth(A,'upper')

% Copyright 2012 The MathWorks, Inc.