Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# how to add two rows of matrix??

Posted on 2007-10-20
Medium Priority
275 Views
Hi,

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??
0
Question by:dkim18

LVL 10

Assisted Solution

ID: 20115998
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.
0

LVL 22

Accepted Solution

JimBrandley earned 1050 total points
ID: 20116499
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);
k++;
}

Jim
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
###### Suggested Courses
Course of the Month14 days, 17 hours left to enroll