Date: Aug 19, 2008 8:20 PM
Author: Alex Reisner
Subject: convert multiple subscripts to linear indices

Here's my problem.  Say I have a 5x5 matrix:
A =
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19 24
5 10 15 20 25

I also have 4 vectors:
m1 = [2 4]
m2 = [3 5]
n1 = [1 3]
n2 = [2 4]

The corresponding elements of each vector specify a
rectangular region in M. For example,
A(m1(1):m2(1),n1(1):n2(1))
i.e. A(2:3,1:2)
and A(m1(2):m2(2),n1(2):n2(2))
i.e. A(4:5,3:4)

In general, each of the 4 vectors can have more than 2
elements, but they always have the same number as each
other. I'd like to assign one value to all regions defined
by the values in those vectors. To do this, I believe I
need to convert the 4 vectors into 1 vector of linear
indices so that I can do:
A(ind) = value

How do I calculate ind from m1, m2, n1, and n2?