# Help me with a matrix in Matlab programming

Status
Not open for further replies.

#### ramone

##### Member level 3
Programmin help!

Hi there i have this matrix:
1 1 1 1 1 -1 -1 -1
1 6 6 6 1 -1 -1 -1
1 6 6 5 1 1 1 1
1 1 1 1 1 1 1 1
1 -1 -1 -1 1 6 6 1
1 -1 -1 -1 1 6 6 1
1 -1 -1 -1 1 1 1 5

what i want to do is to give a special number to each special region:
- you can see 2 regions with 6s and a 5...i want to fill the first of this region
with 2s and the second with 3s

does anyone know the way... i am programming in matlab

#### echo47

Programmin help!

Do you want MATLAB to search for the two regions?

Or do you simply want to replace two fixed rectangular groups of cells with a constant, like this?
Code:
a = [1  1  1  1  1 -1 -1 -1
1  6  6  6  1 -1 -1 -1
1  6  6  5  1  1  1  1
1  1  1  1  1  1  1  1
1 -1 -1 -1  1  6  6  1
1 -1 -1 -1  1  6  6  1
1 -1 -1 -1  1  1  1  5];

a(2:3,2:4) = 2;

a(5:7,6:8) = 3;

a
a =
1     1     1     1     1    -1    -1    -1
1     2     2     2     1    -1    -1    -1
1     2     2     2     1     1     1     1
1     1     1     1     1     1     1     1
1    -1    -1    -1     1     3     3     3
1    -1    -1    -1     1     3     3     3
1    -1    -1    -1     1     3     3     3

#### ramone

##### Member level 3
Re: Programmin help!

I want matlab to search (i want to be automatic for any matrix of this kind)

#### echo47

Programmin help!

You need to more clearly define the search criteria. One example is insufficient. In what ways could the matrix change?

##### Junior Member level 3
Re: Programmin help!

more details should be given or make good logic by considering linear aljebra book. eigen values or so.

##### Full Member level 3
Programmin help!

It looks like you want a simple smoothing matrix. The matrix size you're looking for (the entries higher than 2) have to be clearly defined. But in your example the first 'blotch' is 3 wide by 2 tall and the 2nd one is 3 x 3 You have to more clearly define the nature of the out of range data you're trying to smooth. Specially it's maximum and minimum dimensions and values, and the possible ranges of the data that surrounds them.

Status
Not open for further replies.