?
Solved

concatenate columns c#

Posted on 2011-02-27
10
Medium Priority
?
280 Views
Last Modified: 2012-08-14
Hello i have a list of 1s and 0s List = [1,0,1,0,1,1]
1 means that set of columns is selected and 0 no.
each set of columns maybe differ from the other set since it has different number of columns.

So i want to concatenante all the selected sets together. It's not working I want them to be saved a new 2D array.
0
Comment
Question by:dadadude
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
10 Comments
 

Author Comment

by:dadadude
ID: 34992018
For more Information:
I have a :
List<String[,]> Features

Open in new window


And i added the sets to a list. So now i have a list of 2D arrays as u can see
and then
Int [] index = new int[11];
suppose index = {1,0,1,0,1}
String [,]sub; // is that the right way.
        for (int i = 0; i < index.Count; i++) {
            if (index[i] == 1)
            {
              
             ???????????? HOW CAN I APPEND THE SELECTED 2D ARRAYS TOGETHER???
                     
            }//end if

        }//end for

Open in new window

0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 34993005
Can you explain more clearly what should happen? What you mean "APPEND THE SELECTED 2D ARRAYS"? For example, if index[1] = 1, what arrays you append?! Some examples?
0
 

Author Comment

by:dadadude
ID: 34993067
I'll post the code:
As u can see in the code, i already create a list.

Private List<String [,]> features = new List<String[,]>

Open in new window


so I am adding a 2D-Array to the List features.
the list length is 11.
so suppose that i have index = [1,0,0,0,0,0,0,0,0,0,1]

so i should create a new 2D-array with these Columns.
//1. Hauteur
        String[,] hauteur = new String[obs.GetLength(0), 1];
        for (int i = 0; i < obs.GetLength(0); i++)
        {
            hauteur[i, 0] = obs[i, 1];
        }
        features.Add(hauteur);
        //2. Largeur
        String[,] largeur = new String[obs.GetLength(0), 1];
        for (int i = 0; i < obs.GetLength(0); i++)
        {
            largeur[i, 0] = obs[i, 2];
        }
        features.Add(largeur);
        //3. excentricité
        String[,] excentricite = new String[obs.GetLength(0), 1];
        for (int i = 0; i < obs.GetLength(0); i++)
        {
            excentricite[i, 0] = obs[i, 3];
        }
        features.Add(excentricite);
        //4.densite globale
        String[,] densiteGlobale = new String[obs.GetLength(0), 1];
        for (int i = 0; i < obs.GetLength(0); i++)
        {
            densiteGlobale[i, 0] = obs[i, 4];
        }
        features.Add(densiteGlobale);
        //5. orientation
        String[,] orientation = new String[obs.GetLength(0), 1];
        for (int i = 0; i < obs.GetLength(0); i++)
        {
            orientation[i, 0] = obs[i, 5];
        }
        features.Add(orientation);

        //6.perimetre
        String[,] perimetre = new String[obs.GetLength(0), 1];
        for (int i = 0; i < obs.GetLength(0); i++)
        {
            perimetre[i, 0] = obs[i, 6];
        }
        features.Add(perimetre);
        //7. rapport Fitness
        String[,] rapportFitness = new String[obs.GetLength(0), 1];
        for (int i = 0; i < obs.GetLength(0); i++)
        {
            rapportFitness[i, 0] = obs[i, 7];
        }
        features.Add(rapportFitness);
        //8. compacite
        String[,] compacite = new String[obs.GetLength(0), 1];
        for (int i = 0; i < obs.GetLength(0); i++)
        {
            compacite[i, 0] = obs[i, 8];
        }
        features.Add(compacite);
        //9. densite
        String[,] densite = new String[obs.GetLength(0), 8];

        for (int i = 0; i < obs.GetLength(0); i++)
        {
            for (int j = 8; j < 16; j++)
            {

                densite[i, j - 8] = obs[i, j];

            }
        }
        features.Add(densite);

        //10.orientations contour
        String[,] contour = new String[obs.GetLength(0), 8];
        for (int i = 0; i < obs.GetLength(0); i++)
        {
            for (int j = 16; j < 24; j++)
            {

                contour[i, j - 16] = obs[i, j];
            }
        }
        features.Add(contour);
        //11. Zernike
        String[,] zernike = new String[obs.GetLength(0), 35];
        for (int i = 0; i < obs.GetLength(0); i++)
        {
            for (int j = 24; j < 59; j++)
            {

                zernike[i, j - 24] = obs[i, j];
            }
        }
        features.Add(zernike);

        List<String[,]> matrix = new List<String[,]>();
        
        for (int i = 0; i < index.Count; i++)
        {
            if (index[i] == 1)
            {
                matrix.Add(features[i]);

            }//end if

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:dadadude
ID: 34993078
I don't know if what i did is correct. I created a new List and added the selected Items to it.
is that right. it's in the end of the code.
0
 
LVL 30

Expert Comment

by:anarki_jimbel
ID: 34993344
Because code, it seems, not quite correct, I can't understand what you are trying to achieve.

For example, you last statement is strange:

// see code section - I can't paste it here...

Basically, you don't need a loop, you add just one element if i==1. So, effectively you run:

                matrix.Add(features[1]);

 And your matrix has just one element. matrix and features has same structure, datatype, they are lists of square arrays.
What matrix should represent?

Again, what do you mean by "concatenation"?

for (int i = 0; i < index.Count; i++)
        {
            if (index[i] == 1)
            {
                matrix.Add(features[i]);

            }//end if
        }

Open in new window

0
 

Author Comment

by:dadadude
ID: 34993407
HOPE THAT THIS PICTURE HELP!!!

Sans-titre.jpg
0
 

Author Comment

by:dadadude
ID: 34993412
AS you can see in the picture Index(0) = 1 SO I should take Features[0], and Index(2) = 1, so i should take features(2).
0
 

Author Comment

by:dadadude
ID: 34993424
Bottom Line i want TO Concatenate 2D-arrays by columns.
if matrix1 =
1 2 3 4
1 2 3 4
1 2 3 4

and matrix2 =

5  6 7 8 9
5 6 7 8 0
5 6 7 8 0

so matrix3 = Matrix1 + Matrix2:

1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 0
1 2 3 4 5 6 7 8 0
0
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 1500 total points
ID: 34993706
OK, here is a method to concatenate two rectangular arrays:

Input:
A_0_0   A_0_1   A_0_2  
A_1_0   A_1_1   A_1_2  
A_2_0   A_2_1   A_2_2  

and
B_0_0   B_0_1   B_0_2   B_0_3  
B_1_0   B_1_1   B_1_2   B_1_3  
B_2_0   B_2_1   B_2_2   B_2_3  

Output:

A_0_0   A_0_1   A_0_2   B_0_0   B_0_1   B_0_2   B_0_3  
A_1_0   A_1_1   A_1_2   B_1_0   B_1_1   B_1_2   B_1_3  
A_2_0   A_2_1   A_2_2   B_2_0   B_2_1   B_2_2   B_2_3  
private string[,] concatenate(string[,] ar1, string[,] ar2)
        {
            if (ar1.GetLength(0) != ar2.GetLength(0))
            {
                throw new ArgumentException("Arrays must have same number of rows");
            }
            int rows = ar1.GetLength(0);
            int cols1 = ar1.GetLength(1);
            int cols2 = ar2.GetLength(1);
            string[,] concatenatedArr = new string[rows, cols1 + cols2];
            for (int r = 0; r<rows;r++)
            {
                for (int c1 = 0; c1 < cols1; c1++)
                {
                    concatenatedArr[r, c1] = ar1[r, c1];
                }
                for (int c2 = 0; c2 < cols2; c2++)
                {
                    concatenatedArr[r, cols1+c2] = ar2[r, c2];
                }
            }

            return concatenatedArr;
        }
        private void initialiseArray(string[,] ar, string identifier)
        {
            // initialise
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < ar.GetLongLength(1); j++)
                {

                    ar[i, j] = identifier + "_" + i + "_" + j;
                }
            }
        }

Open in new window

0
 

Author Closing Comment

by:dadadude
ID: 34995260
not bad for an answer. it's ok
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

762 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