[英]MWarray convert double[] to ushort[]
public static double[] ParseDoubleArray(MWArray array)
{
var vector2d = (array as MWNumericArray).ToArray() as double[,];
var vector1d = new double[vector2d.Length];
System.Buffer.BlockCopy(vector2d, 0, vector1d, 0, vector2d.Length * sizeof(double));
return vector1d;
}
this is my function for getting the double[]
from MWArray
however why i do this: 这是我从MWArray
获取double[]
功能,但是为什么我这样做:
prepImage.RawData = Array.ConvertAll(prepRawData, Convert.ToUInt16);
I sometimes get an exception because matlab is returning doubles too big for conversion. 我有时会遇到异常,因为matlab返回的double太大而无法进行转换。
has anyone came across this issue? 有人遇到过这个问题吗? i can crop the numbers but is there another solution? 我可以裁剪数字,但是还有其他解决方案吗?
UInt16
, as its name implies, holds unsigned 16 bit integers (values from 0 to 65535). 顾名思义, UInt16
保存无符号的16位整数(值从0到65535)。 On the other hand, the double
structure ranges from -1.79769313486232e308 to 1.79769313486232e308. 另一方面, double
结构的范围为-1.79769313486232e308至1.79769313486232e308。
The issue here is that your Matlab code returns either a negative value, or a positive value greater than 65535. Matlab will also assign NaN
to any uninitialized value which is also invalid for UInt16
. 这里的问题是您的Matlab代码返回的是负值或大于65535的正值。Matlab还将NaN
分配给任何未初始化的值,这对于UInt16
也是无效的。
To fix your problem, either make sure that your Matlab code is really only returning values in the 0 to 65535 range or change the data structure on the C# side to something else than UInt16
. 要解决您的问题,请确保您的Matlab代码实际上仅返回0到65535范围内的值,或者将C#端的数据结构更改为UInt16
其他值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.