Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Analysis.Math.Statistics fails when NaN values are included in input arrays

Solved!
Go to solution

Hi all..

 

Using Measurement Studio for .Net Version 8.9. We need to calculate the statistics on an array that includes some double.NaN values. When I do this I get NaN as the result from any of the statistics methods (Mean,Std etc) ..interestingly the Math.ArrayOperations methods look like they work. Any ideas?

 

Thanks

 

gdssoftware

0 Kudos
Message 1 of 5
(3,846 Views)

Hi GDSSoftware,

 

That's an interesting find.  What versions of Measurement Studio and Visual Studio are you using?  Does this phenomenon occur for all members of the Statistics and ArrayOperation classes?

 

Regards,

 

Stephanie R.

National Instruments

Stephanie R.
National Instruments
0 Kudos
Message 2 of 5
(3,821 Views)

We are using Measurement Studio for .Net 8.9.35.246 with Visual Studio 2008 sp1.

 

Looks like version 9.X also has the problem....

 

GDSSoftware

 

 

0 Kudos
Message 3 of 5
(3,702 Views)
Solution
Accepted by topic author GDSSoftware

Hi GDSSoftware,

 

You are seeing this behavior because statistics functions with Measurement Studio do not ignore NaN input values -- therefore, they will return NaN results.  In order to get around this, you will need to filter these NaN values out of your input array before you perform statistical analysis on it. 

 

If you are working with .NET 3.5 and later, you can do this by using the following:

 

double[] vals = new double[] { 10d, 0d, 6d, 4d, double.NaN };
double[] nanless_vals = vals.Where(d => !double.IsNaN(d)).ToArray();

 

If you are working with earlier version of the .NET framework, then you will need to loop through the array with the following (or something similar):

 

double[] vals = new double[] { 10d, 0d, 6d, 4d, double.NaN };
List<double> nanless_list = new List<double>();
for (int i = 0; i < vals.Length; i++)
    if (!double.IsNaN(vals[i]))
        nanless_list.Add(vals[i]);
double[] nanless_vals = nanless_list.ToArray();

 

Hope this helps!

 

 

Regards,

 

Stephanie R.

National Instruments

Stephanie R.
National Instruments
0 Kudos
Message 4 of 5
(3,683 Views)

Thanks Stephanie..Already doing the removals. 

 

But I do think that IEEE NaN compatibility should be added to the statistical functions in the next measurement studio release version.

 

Regards,

 

 

0 Kudos
Message 5 of 5
(3,677 Views)