Go Down

### Topic: Formula for addressing cell in a Matrix (Read 1 time)previous topic - next topic

#### ktz

##### Jun 10, 2011, 03:30 pm
Hi everyone,

I feel a little stupid as I am sure I covered this in my algebra classes on numerous occasion when I was younger, but I am struggling to find the formula that allows cell addressing in a matrix. For example, how do I find the cell number for the cell that is on column 5, row 4 of an 8x8 matrix ?

Any help would be greatly appreciated. If you need more clarity, let me know.

best,
Joel

#### CrossRoads

#1
##### Jun 10, 2011, 03:44 pm
Formula? Wouldn't you have defined an array
matrix[8,8]
and then just read/write the elements from there?

getting a value from the matrix:
value_out=matrix[row, column]

putting a value into the matrix
matrix[row,column] = value_in

Do a loop within a loop to access all 64 in one shot, with this code concept:

for (row = 0 to 7)
for (column = 0 to 7)
matrix[row, column]=row*7 + column;
nextcolumn
next row

for (row = 0 to 7)
for (column = 0 to 7)
value = matrix[row, column]
Serial.print (value)
nextcolumn
next row
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### Magician

#2
##### Jun 10, 2011, 04:03 pm
Code: [Select]
`for (row = 0 to 7)   for (column = 0 to 7)        matrix[row, column]=row*7 + column;   nextcolumnnext rowfor (row = 0 to 7)   for (column = 0 to 7)        value = matrix[row, column]        Serial.print (value)   nextcolumnnext row`
Is it Pascal?  In C different syntax, but the idea is clear.

#### AWOL

#3
##### Jun 10, 2011, 04:13 pm
Quote
matrix[row, column]=row*7 + column;

Why seven?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### wildbill

#4
##### Jun 10, 2011, 05:23 pm
As others have said above, not sure why you would need this in an Arduino context, but this is what you're asking for I think:

row*8+column

#### CrossRoads

#5
##### Jun 10, 2011, 05:51 pm
Yes, had 0-7 on the brain, 8 is correct.

I find using the "code concept"  vs the actual command makes it easier to visualize, for me anyway:

for (int i=0; i <= 255; i++){
..
}
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

#### ktz

#6
##### Jun 13, 2011, 05:56 pm

row*8+column

Thanks so much Bill (and all), this is precisely what I was after. And yes, it's so logical that I feel really stupid. I was making it much more difficult on myself.

In regards to why I would need this, it pertains to the output that I need to address (being an x by x matrix that is addressable via numbers 0 -< total, in my case, 64). The conversation was great here though and it really made me realise that I need to read up on multidimensional arrays a bit. They seem like they could come in real handy!

Thanks again everyone for the help and direction.

Go Up