Assuming c1[0]=20 and c2[0]=250, Nrow=8 and Ncol=5, the matrix for red calculated by the above code will be the RESULT 1 below.
So, first color c1[0]=20 will appear in cel (1,1) and c2[0] in cel (8,5). Of course, Nrow can be equal to Ncol. Please note first col and first row have the same repeated value.
If it is required a linear variation in the first row and col, then factor should be:
factor = ((row-1)+(col-1))/(float)((Nrow-1)+(Ncol-1));
That way, the result matrix, for the same parameters as before, will be as in RESULT 2 below.
Jose