Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to make two dimensional arrays from one dimensional arrays?

I would like to know how to make a two-dimensional array from a couple of one-dimensional arrays. I am not familar with array and arraylist of C#. Please teach me.

Now, I am doing as follows. But, I think it is not very efficient method.

double [,] twoArray = new double(rank,length);

for (int m=0; m{
double [] oneArray = signalGenerator.Generate();
for (int n=0; n {
twoArray[m,n] = oneArray[n];
}
}
0 Kudos
Message 1 of 2
(3,455 Views)
Try using Buffer.BlockCopy.
On an average, its aways faster than doing a point by point copy.

double [,] test = new double[2,ARRAYSIZE];
Random randy = new Random();
double[] one = new double[ARRAYSIZE];
double[] two = new double[ARRAYSIZE];

//Populate data
for(int i =0;i < ARRAYSIZE;i++)
{
one[i] = randy.NextDouble();
two[i] = randy.NextDouble();
}

int elementSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(double));

Buffer.BlockCopy(one,0,test,0,elementS
ize*ARRAYSIZE);
Buffer.BlockCopy(two,0,test,elementSize*ARRAYSIZE,elementSize*ARRAYSIZE);

If you want to benchmark the results, this article provides code for a high resolution timer.

Hope this helps

Bilal Durrani
NI
Bilal Durrani
NI
Message 2 of 2
(3,455 Views)