# Math Help - Formula to calculate indexes from row and column

1. ## Formula to calculate indexes from row and column

This is as much about programming as it is software, but I thought there might be a nifty way to do it with excel that I'm unaware of.

I have two sets of numbers, indexes for rows and columns, and I need to map them to indexes. Rather than actually setting the cell values, I'm trying to get them 'on-the-fly', but I can't get the formula to work.

Eg:
Code:
Row	Col	Index
0	0	0
0	1	1
0	2	2
0	3	3
0	4	4
1	0	5
1	1	6
1	2	7
1	3	8
1	4	9
2	0	10
2	1	11
2	2	12
2	3	13
2	4	14
3	0	15
3	1	16
3	2	17
3	3	18
3	4	19
I need a formula which will always return the index when it's given the row and column, but I can't find one that works.

Here's a spreadsheet if you fancy playing around with it.

2. 5*Row + Col, where 5 = number of columns

To judge from your file, what you have tried to do is:

$index = \left\{\begin{array}{ll}2row+col,&\mbox{ if }
row=0\\2row^2+2+col, & \mbox{ if } row\neq 0\end{array}\right.$

How did you come up with those formulas? :P