02-08-2011 10:02 AM
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
Solved! Go to Solution.
02-09-2011 10:55 PM
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
04-08-2011 06:50 AM
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
04-11-2011 11:01 AM
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
04-11-2011 01:14 PM
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,