- Do you want a new a where the value is 1 inside your boundaries, essentially a binary map or image of what elements are inside the shape you drew?
- Or do you want to "erase" (replace by 0) half the "bande"? If so, which half: the lower or upper half of that shape should be zeroed out?
- Or do you want a list of (row, column) coordinates of inside the shape?

# how to found bandes matrix

5 views (last 30 days)

Show older comments

i have a big matrix with 2000x2000

to solve this equation

i need to use only a bandes matrix or half of bandes

i need te have only a bandes matrix without aij equal zero

i found sparse but i dont inderstand how to use it

i need to found this

for exemple

a=[

9 -2 0 -2 0 0 0 0

-2 9 -2 0 -2 0 0 0

0 -2 9 -2 0 -2 0 0

-2 0 -2 9 -2 0 -2 0

0 -2 0 -2 9 -2 0 -2

0 0 -2 0 -2 9 -2 0

0 0 0 -2 0 -2 9 -2

0 0 0 0 -2 0 -2 9]

##### 1 Comment

Image Analyst
on 7 Oct 2020

Not sure what you want.

Please define exactly what "half of bandes" means to you.

### Answers (1)

John D'Errico
on 7 Oct 2020

Edited: John D'Errico
on 7 Oct 2020

You have 5 non-zero bands. Use spdiags. Yes, you could use sparse. But since it is a banded matrix, use a tool to breate a banded matrix.

n = 2000;

A = spdiags(repmat([-2 -2 9 -2 -2],[n 1]),[-3 -1 0 1 3],n,n);

Did it work?

full(A(1:10,1:10))

So the 10x10 square in the upper left corner looks right.

spy(A(1:50,1:50))

And it is indeed banded properly.

You will need to learn to use tools like sparse, and I hope, learn them quickly if you are working with sparse matrices to any extent. But learn to use the proper tools to solve your problem.

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!