I have two arrays (eut1 and eut2) that are rather large and i want to merge them to create a new one containing one after the other. I create the new array but i dont know how to assign eut1 and eut2 to the anglesEut so they end up after each other.
public void setgetAnglesEut(float[,] eut1, float[,] eut2)
{
this.anglesEut = new float[eut1.GetLength(0) + eut2.GetLength(0), eut2.GetLength(1)];
this.anglesEut = eut1;
// when anglesEut is assigned eut1 it also gets its dimentions. How do i add eut2 efter eut1.
// eut1 and eut 2 have the following dimentions
// Eut1 {float[3, 4096]}
// anglesEut {float[6, 4096]}
}
Loading
JurePosted Nov 5, 2010, 7:54 AM
List
> result = new List
>(list1);
result.AddRange(list2);
;)
Nils GustavssonPosted Nov 5, 2010, 7:43 AM
JurePosted Nov 4, 2010, 11:59 AM
{
float[,] arr1 = new float[3, 2] { { 0, 12 }, { 1, 25 }, { 2, 45 } };
float[,] arr2 = new float[3, 2] { { 0, 9 }, { 1, 17 }, { 2, 29 } };
int d1 = arr1.GetLength(0) + arr2.GetLength(0);
int d2 = arr1.GetLength(1) > arr2.GetLength(1) ? arr1.GetLength(1) : arr2.GetLength(1);
float[,] result = new float[d1, d2];
AddToArray(result, arr1);
AddToArray(result, arr2, arr1.GetLength(0));
for (int i = 0; i < result.GetLength(0); ++i)
{
for (int j = 0; j < result.GetLength(1); ++j)
{
Console.Write(result[i, j] + " ");
}
Console.WriteLine();
}
Console.ReadKey();
}
static void AddToArray(float[,] result, float[,] array, int start = 0)
{
for (int i = 0; i < array.GetLength(0); ++i)
{
for (int j = 0; j < array.GetLength(1); ++j)
{
result[i + start, j] = array[i, j];
}
}
}
It's a bit more complicated than I thought. There are no simple conversions from [,] array, since this type of array is not multi-dimensional in the same way that the others are, for example List
> or int[][], where you have list of lists or pointer of pointers.
Nils GustavssonPosted Nov 4, 2010, 10:48 AM
anglesEut = (float[,])eut1.Clone();
Clone() sems like it dose what i want to do but i also want to add the data in eut2 after eut1.
eut1
0, 12
1, 25
2, 45
eut2
0, 9
1, 17
2, 29
anglesEut
0 12
1 25
2 45
0 9
1 17
2 29
JurePosted Nov 4, 2010, 10:02 AM
123
456
array2:
78
99
12
Do you want this:
12378
45699
12
or this:
12378
45699
00012
"this.anglesEut = eut1;" - this simply makes anglesEut reference to the the eut1. You have to clone the array:
anglesEut = (float[,])eut1.Clone();
In any case, it'll be simpler to use list with its AddRange method. List can then return an array copy of itself.