Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Does anyone have a usage example of AnalogWaveform.From2DArray in C#?

I am attempting generate simulation data for my application and wanted to not use the brute force approach.  This led me to the 'From2DArray' method- the help description is 'Creates an AnalogWaveform<TData> array from a two-dimensional array of values.....Parameters array The two-dimensional array of values.'  All attempts have resulted in 'cannot implicitly convert' errors.  I had assumed that method would take a 2D array of values (number of samples x number of channels) and populate an AnalogWaveform with this information leaving me to append timing information via AnalogWaveform.Timing property.  Anyone used this method that can share a code snippet?  Alternatively, does anyone have a complete description of the structure inside and AnalogWaveform?  Thanks-
0 Kudos
Message 1 of 4
(4,432 Views)
Hi JDPZRQ47X,

I had a Form with a button and a WaveformGraph control. When you clicked the button, it did the following:

DateTime[] times;
Random rnd = new Random();

// Initialize the Date-Time array
times = new DateTime[5];
times[0] = new DateTime(1970, 1, 1, 0, 0, 0);
for (int i = 1; i < 5; i++)
    times[i] = times[0].AddMilliseconds(i);

double[,] data = new double[5, 5];

for (int i = 0; i < 5; i++)
    for (int j = 0; j < 5; j++)
        data[i, j] = rnd.NextDouble();
   
AnalogWaveform<double>[] waveform = AnalogWaveform<double>.FromArray2D(data);

// Add some timing information
foreach (AnalogWaveform<double> wfm in waveform)
{
    wfm.Timing = WaveformTiming.CreateWithIrregularInterval(times);
}

waveformGraph1.PlotWaveforms(waveform);


This worked for me

Best Regards,
Jonathan N.
National Instruments
Message 2 of 4
(4,426 Views)

Hi Jonathon- thanks much, your code has illuminated the issue.  As usual the problem was simple- syntax error.  My code similar to yours (before reviewing your work, even more so after!!) - the critical line that was causing the problem was this (note the presence of the comma in the type):  Thanks very much.

AnalogWaveform<double>[,] fakeWaveform = AnalogWaveform<double>.FromArray2D(fakeData);

0 Kudos
Message 3 of 4
(4,420 Views)

Yeah, simple syntax errors can drive you nuts for hours.Smiley Very Happy  Glad I could help!

Best Regards,

Jonathan N.
National Instruments
0 Kudos
Message 4 of 4
(4,417 Views)