Skip to content

isbanded

Determine if a matrix is banded

isband(A, l, u)

  • A should be a matrix.
  • l and u should be non-negative real integers.
  • It returns logical 1 if elements lying above the u-th diagonal and elements lying below the l-th diagonal are all zero.
  • It returns logical 1 if A is empty.

Example 1: Test if a randomly generated matrix (30% of its entries are non-zero) has lower and upper bandwidths equal to 3 and 1, respectively.

a=zeros([5 4]);
i=randi(numel(a),1,ceil(numel(a)*.3));
a(i)=7+7i
isbanded(a,3,1)
a =
 0.000 + 0.000i   7.000 + 7.000i   0.000 + 0.000i   0.000 + 0.000i
 0.000 + 0.000i   7.000 + 7.000i   0.000 + 0.000i   0.000 + 0.000i
 0.000 + 0.000i   7.000 + 7.000i   0.000 + 0.000i   0.000 + 0.000i
 7.000 + 7.000i   0.000 + 0.000i   0.000 + 0.000i   7.000 + 7.000i
 0.000 + 0.000i   0.000 + 0.000i   0.000 + 0.000i   0.000 + 0.000i

ans =
 1