how to add two rows of matrix??


I have this matrix and how can I do this addition of two rows of matrix systematically in c#??

Say I have a matrix of Ma[10,20] and I want to cut this matrix to newMa[5,20]
In order to do that, I want to add two rows and get the average and put it into the newMa.

As example,

2   4   3                                       3     5     5
4    6   7                 to                  3     8     8
3    4   3
3    12  13

Does this make any sense??
Who is Participating?
It sounds like you are looking for the midpoints. This would be more interesting and generally useful if your matrix were defined as an array or list of vecoors. However, this will build that matrix for your sample values:

int[,] matrix = new int[,]{
   {2,4,3}, {4,6,7}, {3,4,3}, {3,12, 13}};
int[,] midpoints = new int[2, 3];
int k = 0;
for (int i = 0; i < 4; i += 2)
   for (int j = 0; j < 3; j++)
      midpoints[k, j] = matrix[i, j] + ((matrix[i + 1, j] - matrix[i, j]) / 2);

It makes sense if you have some requirement for this. One question which rows do you want to retain and where should the avg. be replaced in the matrix. if it is the lower rows you want to retain then you need to loop through the array from top to required lower position -1 and add all the number take out the average of the numbers and then replace the result in required lower position.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.