Wavecom W-BitView V2.5.00 User Manual
Page 79
BitView Manual V2.5.00 WAVECOM W-BV
Custom Library
73
get
{
return (outpar5);
}
}
// add more Calculation properties here
// ...
#endregion
#region Constructor
///
/// Constructor
///
public BVCustLibMatlab()
{
// add initialisation code if necessary
}
#endregion
#region calculation function
///
/// // THE calculate function. Do not change name or parameter! This function will be
searched for
/// by reflection and called for execution, when this library is added to an
analysis.
///
public BitArray Calculate(BitArray buf)
{
if (buf == null)
return (null);
if (buf.Count <= 0)
{
outbox.Length = 0;
return (outbox);
}
//---------------------------------------------------------------------
// any calculation goes here
//---------------------------------------------------------------------
try // catch any exception from matlab dll. If calling the matlab function
fails, we do not crash the app
{
// Generate data arrays for MatLab function.
// Data input for matlab function is derived from buf, which is type of
BitArray
// MatLab has not a compatible data type, so we have to convert BitArray buf
// into the MatLab default numeric type double 0.0 and 1.0
// new instance of a MatLab numeric array with a size of [buf.Length,1]
MWNumericArray
data
=
new
MWNumericArray(MWArrayComplexity.Real,
MWNumericType.Double, new int[] { buf.Length, 1 });
// Initialize data from BitArray buf
// MatLab index range is from 1...n, in C# it is from 0 ... (n-1)
for (int idx = 1; idx <= buf.Length; idx++)
{
data[idx, 1] = buf[idx - 1] ? 1.0 : 0.0;
}
// data output from matlab function is an Array of arguments
MWArray[] argsOut = null;
// prepare for calling the MatLab function, create an instance of the MatLab
function class
// generated by the MatLab deploytool, use Intellisense in visual studio,
then you see
// the list of classes found up to now in this project. Our example is
// MatLab function called 'MatlabFunction' in the .m File with the same name.
// Here is the complete listing of the MatLab .m File:
/*---------------------------------------------------------------------------
--------------------