How to check a matrix is multibanded?

1 次查看(过去 30 天)
I have a sparse matrix which I need to verify whether it is multibanded or not?

回答(1 个)

Chunru
Chunru 2021-9-21
% Create a banded sparse matrix
B = bucky;
r = symrcm(B)
r = 1×60
1 6 2 5 7 26 30 10 11 12 3 4 8 27 29 9 15 13 16 17 21 25 42 28 43 38 37 14 20 18
a=B(r,r);
imagesc(a);
% Check if it is banded
m = size(a,1); % assuming square matrix
lb = m;
ub = m;
for i=-m+1:0
% check the diagonal
if all(diag(a, i)==0)
lb = i;
else
break
end
end
for i=m-1:-1:0
% check the diagonal
if all(diag(a, i)==0)
ub = i;
else
break
end
end
[lb, ub]
ans = 1×2
-12 12

类别

Help CenterFile Exchange 中查找有关 Sparse Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by