I'm having problems generalizing a number sequence. It involves a couple parameters that I will attempt to explain and show by example.(adsbygoogle = window.adsbygoogle || []).push({});

Basically I have a program that takes 3x3 raster segments of a much bigger matrix. The matrix is a logical matrix. What I do is take the a 3x3 raster segment and compare it to a library of 3x3 patterns. I check to see if this particular segment matches any of the 3x3 patterns in the library. This happens until the rastering process is over.

If a match is made in the library, I need to place a marker in the original matrix. The marker is always in the center of the raster segment (2,2) and at different locations in the original matrix depending on what number raster it is.

I need to come up with a generalized equation for any size original matrix such that I can compute the row and column location in the original matrix of the center point in the raster segment. In other words transform the center point (2,2) in the raster segment to it's corresponding point in the original matrix.

Note: The logical matrix is read as a column in matrix M such that every column represents a raster segment.

For example in the original matrix [O]:

Raster segment matrixCode (Text):O = [0 1 0 1 1;

1 0 1 1 1;

1 0 1 0 1;

1 1 0 0 1;

1 1 1 0 1];

Each column represents a raster segment read row wise (every pair of 3 in a column of M = a row in the raster segment).Code (Text):M = [0 1 0 1 0 1 1 0 1;

1 0 1 0 1 1 0 1 0;

0 1 1 1 1 1 1 0 1;

1 0 1 1 0 1 1 1 0;

0 1 1 0 1 0 1 0 0;

1 1 1 1 0 1 0 0 1;

1 0 1 1 1 0 1 1 1;

0 1 0 1 0 0 1 1 0;

1 0 1 0 0 1 1 0 1];

So for the first segment (column 1),

For this example the locations of the center (2,2) for the raster segments 1 - 9 are as follows:Code (Text):Seg1 = [0 1 0;

1 0 1;

1 0 1];

Raster Segment# = (row,col)

1 = (2,2)

2 = (2,3)

3 = (2,4)

4 = (3,2)

5 = (3,3)

6 = (3,4)

7 = (4,2)

8 = (4,3)

9 = (4,4)

At first I was thinking about using a logical statement like so in where I compare the segment number (Sn) to a listing. any() checks to see if any of the equivalencies are true; returns a 1 for true, 0 for false.

So for example, if I am on Sn = 2, the calculation for row and column would be as followsCode (Text):row = 2*(any(Sn == [1 2 3])) + 3*(any(Sn == [4 5 6])) + 4*(any(Sn == [7 8 9]));

col = 2*(any(Sn == [1 4 7])) + 3*(any(Sn == [2 5 8])) + 4*(any(Sn == [3 6 9]));

row = 2*(1) + 3*(0) + 4*(0) = 2

col = 2*(0) + 3*(1) + 4*(0) = 3

location of (2,2) in original matrix is (2,3)

Here's the problem with this approach. For any size [O], I will have more array checks. For instance, if I were to have a 6x6 original matrix the number of raster segments would be 16. This is found by the following relation:

# of possible horizontal rasters = row size of [O] - 2

# of possible vertical rasters = column size of [O] - 2

So 4 raster segments are possible for horizontal scanning and 4 for vertical scanning.

The row and column equations would then become:

row = 2*(any(Sn == [1 2 3 4])) + 3*(any(Sn == [5 6 7 8])) + 4*(any(Sn == [9 10 11 12])) + 5*(any(Sn == [13 14 15 16]));

col = 2*(any(Sn == [1 5 9 13])) + 3*(any(Sn == [2 6 10 14])) + 4*(any(Sn == [3 7 11 15])) + 5*(any(Sn == [4 8 12 16]));

For obvious reasons this won't work as nicely as I thought. So now I'm trying to figure out a mathematical relation or perhaps generate a table. I'm using MATLAB to do this and would appreciate any suggestions.

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Problems generalizing a number sequence

**Physics Forums | Science Articles, Homework Help, Discussion**