static MxArray _MxArrayFromInt16Array( Array value) { int count = value.Length; int[] arraydims = MxUtils.GetArrayDimensions(value); int[] dims; if (value.Rank == 1) { dims = new int[] { 1, count }; } else { dims = (int[])arraydims.Clone(); } MxArray result = MxArray.CreateArray(dims, ClassID.Int16, Complexity.Real); unsafe { short *pr; pr = (short *)result.RealElements; for (int i = 0; i < count; i++) { *pr++ = (short) value.GetValue(MxUtils.CoordinatesFromIndex(i, arraydims)); } } return(result); }
static MxArray _MxArrayFromInt16Array_Cplx( Array value) { int count = value.Length; int[] arraydims = MxUtils.GetArrayDimensions(value); int[] dims; if (value.Rank == 1) { dims = new int[] { 1, count }; } else { dims = (int[])arraydims.Clone(); } MxArray result = MxArray.CreateArray(dims, ClassID.Int16, Complexity.Complex); unsafe { short *pr, pi; pr = (short *)result.RealElements; pi = (short *)result.ImaginaryElements; Complex <short> currentValue; for (int i = 0; i < count; i++) { currentValue = (Complex <short>) value.GetValue(MxUtils.CoordinatesFromIndex(i, arraydims)); *pr++ = currentValue.RealPart; *pi++ = currentValue.ImaginaryPart; } } return(result); }
public int[] CoordinatesFromIndex(int index) { CheckPointer(); return(MxUtils.CoordinatesFromIndex(index, Dimensions)); }