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
2
Medium Priority
?
275 Views
Last Modified: 2010-04-15
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
Comment
Question by:dkim18
2 Comments
 
LVL 10

Assisted Solution

by:answer_me
answer_me earned 450 total points
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

by:
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

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

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

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question