标签:
在外部编程语言与matlab的交互中,Array是最单元的交互元素,怎么都绕不过去。
在matlab提供的Array接口有两个,一个是C的MxArray, 另一个是Cpp(C++)的MwArray.
看下两着的分别介绍:
mxArray:Matlab C 函数库的结构体
mwArray:Matlab C++ 函数库中对mxArray的包装类
声明:
mxArray: mxArray *a;
mwArray: mwArray a;
销毁
mxArray: mxDestroyArray a;
mwArray: mwArray类的析构函数自动销毁对象
变量传递
mxArray: mxArray *dest_ptr =mxCreateDoubleMatrix(rows,cols, mxREAL);
memcpy(dest_ptr,source_ptr,MAX_SIZE);
mwArray: mwArray in1(rows, cols, mxDOUBLE_CLASS, mxREAL);
mwArray in2(rows, cols, mxDOUBLE_CLASS, mxREAL);
in1.SetData(data, rows*cols);
in2.SetData(data, rows*cols);
比较而言, 1。mwArray的声明更简洁,不用考虑指针 2。mwArray不用手动释放内存
mxArray *mxCreateDoubleMatrix(int m, int n, mxComplexity ComplexFlag);
参数m和n为矩阵的函数和列数。ComplexFlag为常数,用来区分矩阵中元素是实数还是复数,取值分别为mxREAL和mxCOMPLEX。
类似的创建函数还有:
mxArray *mxCreateString(const char *str); 创建一个字符串类型并初始化为str字符串。
对应的,要删除一个数组mxDestroyArray,该函数声明如下:
void mxDestroyArray(mxArray *array_ptr);
要获得mxArray数组每一维上元素的个数,可以用mxGetM和mxGetN函数。其中mxGetM用来获得数组第一维的元素个数,对于矩阵来说就是行数。
int mxGetM(const mxArray *array_ptr); //返回array_ptr对应数组第一维的元素个数(行数)
int mxGetN(const mxArray *array_ptr); //返回array_ptr对应数组其它维的元素个数,对于矩阵来说是列数。对于多维数组来说是从第2维到最后一维的各维元素个数的乘积。
要获得某一特定维的元素个数,则要用函数:
const int *mxGetDimensions(const mxArray *array_ptr);
该函数返回array_ptr各维的元素个数保存在一个int数组中返回。对于常用的矩阵来说,用mxGetM和mxGetN两个函数就可以了。
另外还可以通过mxGetNumberOfDimensions来获得数组的总的维数,用mxSetM、mxSetN设置矩阵的行数和列数,函数说明如下:
int mxGetNumberOfDimensions(const mxArray *array_ptr); //返回数组的维数
void mxSetM(mxArray *array_ptr, int m); //设置数组为m行
void mxSetN(mxArray *array_ptr, int n); //设置数组为n列
在对mxArray类型的变量进行操作之前,可以验证以下其中的数组的数据类型,比如是否为double数组、整数、字符串、逻辑值等,以及是否为某种结构、类、或者是特殊类型,比如是否为空数组,是否为inf、NaN等。常见的判断函数有:
Use these functions to validate input arguments.
C Functions
mxIsDouble | Determine whether mxArray represents data as double-precision, floating-point numbers |
mxIsSingle | Determine whether array represents data as single-precision, floating-point numbers |
mxIsComplex | Determine whether data is complex |
mxIsNumeric | Determine whether array is numeric |
mxIsInt64 | Determine whether array represents data as signed 64-bit integers |
mxIsUint64 | Determine whether array represents data as unsigned 64-bit integers |
mxIsInt32 | Determine whether array represents data as signed 32-bit integers |
mxIsUint32 | Determine whether array represents data as unsigned 32-bit integers |
mxIsInt16 | Determine whether array represents data as signed 16-bit integers |
mxIsUint16 | Determine whether array represents data as unsigned 16-bit integers |
mxIsInt8 | Determine whether array represents data as signed 8-bit integers |
mxIsUint8 | Determine whether array represents data as unsigned 8-bit integers |
mxIsScalar | Determine whether array is scalar array |
mxIsChar | Determine whether input is mxChar array |
mxIsLogical | Determine whether array is of type mxLogical |
mxIsLogicalScalar | Determine whether scalar array is of type mxLogical |
mxIsLogicalScalarTrue | Determine whether scalar array of type mxLogical is true |
mxIsStruct | Determine whether input is structure array |
mxIsCell | Determine whether input is cell array |
mxIsClass | Determine whether array is member of specified class |
mxIsInf | Determine whether input is infinite |
mxIsFinite | Determine whether input is finite |
mxIsNaN | Determine whether input is NaN (Not-a-Number) |
mxIsEmpty | Determine whether array is empty |
mxIsSparse | Determine whether input is sparse array |
mxIsFromGlobalWS | Determine whether array was copied from MATLAB global workspace |
对于常用的double类型的数组,可以用mxGetPr和mxGetPi两个函数分别获得其实部和虚部的数据指针,这两个函数的声明如下:
double *mxGetPr(const mxArray *array_ptr); //返回数组array_ptr的实部指针
double *mxGetPi(const mxArray *array_ptr); //返回数组array_ptr的虚部指针
Utilities for manipulating strings and structures.
C Functions
mxArrayToString | Array to string |
mxArrayToUTF8String | Array to string in UTF-8 encoding |
mxGetString | mxChar array to C-style string or Fortran character array |
//为了调用matlab中的函数,必须使用数组数据类型,并其后调用matlab函数将其转化为矩阵格式(matlab的基本数据类型是矩阵) static double x1[1]={1.0}; static double x2[1]={2.5}; double result; //调用matlab创建3个矩阵 mxArray *A=mclGetUninitializedArray(); mxArray *B=mclGetUninitializedArray(); mxArray *C=mclGetUninitializedArray(); //将C语言中的变量值赋给matlab中的矩阵 mlfAssign(&A,mlfDoubleMatrix(1,1,x1,NULL)); mlfAssign(&B,mlfDoubleMatrix(1,1,x2,NULL)); mlfAssign(&C,mlfMyfunct(A,B)); //调m函数 //将matlab中的矩阵的指针传递给C语言中的指向double的指针 double * md=mxGetPr(C); result=md[0]; //释放这些矩阵 mxDestroyArray(A); mxDestroyArray(B); mxDestroyArray(C);
mwArray | Class used to pass input/output arguments to C functions generated by MATLAB Compiler SDK |
mwException | Exception type used by the mwArray API and the C++ interface functions |
mwString | String class used by the mwArray API to pass string data as output from certain methods |
mwArray() Description 创建空的Matlab阵列,类型为mxDOUBLE_CLASS
mwArray(mxClassID mxID) Description 创建mxID指定类型的Matlab阵列
Arguments
mwArray(mwSize num_rows, mwSize num_cols, mxClassID mxID, mxComplexity cmplx = mxREAL)
mwArray(mwSize num_dims, const mwSize* dims, mxClassID mxID, mxComplexity cmplx = mxREAL)
创建任意维数的Matlab阵列,维数由num_dims指定,各维大小由dims指定,mxID指定阵列的类型。对于数值型阵列,将cmplx作为最后的一个参数,确定待创建阵列是否为复型的阵列。
All elements are initialized to zero. For cell arrays, all elements are initialized to empty cells.
mwArray(const char* str)
Create a 1-by-n
array of type mxCHAR_CLASS
,
with n = strlen(str)
, and initialize the array‘s data with the characters in the supplied string.
根据字符串str创建一个新的字符型阵列
创建字符型阵列(mxCHAR_CLASS),字符串由str指定. The created array has dimensions m-by-max, where max
is the length of the longest string in str
.
mwArray(mwSize num_rows, mwSize num_cols, int num_fields, const char** fieldnames)
Create a matrix of type mxSTRUCT_CLASS
, with the specified field names. All elements are initialized
with empty cells.
创建行数为num_rows,列数为num_cols结构体阵列(mxSTRUCT_CLASS), 结构体域名为由fieldnames指定,域名个数由num_fields指定
mwArray(mwSize num_dims, const mwSize* dims, int num_fields, const char** fieldnames)
Create an n
-dimensional array of type mxSTRUCT_CLASS
,
with the specified field names. All elements are initialized with empty cells.
创建任意维数的结构体阵列,维数由num_dims指定,各维大小由dims指定,结构体域名由fieldnames指定,域名个数由num_fields指定.
mwArray(const mwArray& arr)
Create a deep copy of an existing array. 根据当前的阵列arr中创建一个新的阵列(复制)
mwArray(<type> re)
Create a real scalar array. 创建一个新的数值阵列,实部为re.
The scalar array is created with the type of the input argument.
mwArray(<type> re, <type> im)
Create a complex scalar array. 创建一个新的数值阵列,实部为re,虚部为im
The scalar array is created with the type of the input argument.
<type>
can be any of the following: mxDouble\mxSingle\mxInt8\mxUint8\mxInt16\mxUint16\mxInt32\mxUint32\mxInt64\mxUint64\mxLogical
mwArray Clone() const
Create a new array representing deep copy of array.
mwArray SharedCopy() const
Create a shared copy of an existing array. The new array and the original array both point to the same data.
返回一个新的共享数据型mwArray阵列,此阵列与现有的mwArray阵列指向同一个数据块。
mwArray Serialize() const
Serialize an array into bytes. A 1-by-n
numeric matrix of type mxUINT8_CLASS
is
returned containing the serialized data. The data can be deserialized back into the original representation by calling mwArray::Deserialize()
.
将mwArray序列化一个新的阵列,新的阵列为mxUINT8_CLASS类型
mxClassID ClassID() const
Determine the type of the array. See the Work with mxArrays for
more information on mxClassID
.
int ElementSize() const
Determine the size, in bytes, of an element of array type.
返回mwArray阵列元素大小
size_t ElementSize() const
Determine the size, in bytes, of an element of array type.
mwSize NumberOfElements() const
Determine the total size of the array.
返回阵列中元素的个数
mwSize NumberOfNonZeros() const
Determine the size of the of the array‘s data. If the underlying array is not sparse, this returns the same value as NumberOfElements()
.
返回稀疏阵列非零元素的个数
mwSize MaximumNonZeros() const
Determine the allocated size of the of the array‘s data. If the underlying array is not sparse, this returns the same value as NumberOfElements()
.
返回稀疏阵列中最大的元素的个数
mwSize NumberOfDimensions() const
Determine the dimensionality of the array. 返回阵列维数
int NumberOfFields() const
Determine the number of fields in a struct
array. If the underlying array is not of type struct
,
zero is returned.
返回结构体域个数
mwString GetFieldName(int index)
Determine the name of a given field in a struct
array. If the underlying array is not of type struct
,
an exception is thrown.
mwArray GetDimensions() const
Determine the size of each dimension in the array. The size of the returned array is 1-by-NumberOfDimensions()
.
bool IsEmpty() const
Determine if an array is empty.
bool IsSparse() const
Determine if an array is sparse.
bool IsNumeric() const
Determine if an array is numeric.
bool IsComplex() const
Determine if an array is complex.
bool Equals(const mwArray& arr) const
Returns true
if the input array is byte-wise equal to this array. This method makes a byte-wise comparison
of the underlying arrays. Therefore, arrays of the same type should be compared. Arrays of different types will not in general be equal, even if they are initialized with the same data.
int CompareTo(const mwArray& arr) const
Compares this array with the specified array for order. This method makes a byte-wise comparison of the underlying arrays. Therefore, arrays of the same type should be compared. Arrays of different types will, in general, not be ordered equivalently, even if they are initialized with the same data.
int HashCode() const
Constructs a unique hash value form the underlying bytes in the array. Therefore, arrays of different types will have different hash codes, even if they are initialized with the same data.
mwString ToString() const
Returns a string representation of the underlying array. The string returned is the same string that is returned by typing a variable‘s name at the MATLAB command prompt.
mwArray RowIndex() const
Returns an array of type mxINT32_CLASS
representing the row indices (first dimension) of this array.
For sparse arrays, the indices are returned for just the non-zero elements and the size of the array returned is 1-by-NumberOfNonZeros()
.
For nonsparse arrays, the size of the array returned is 1-by-NumberOfElements()
, and the row indices
of all of the elements are returned.
返回阵列元素的行索引;对于稀疏阵列,只返回非零原素的行索引
mwArray ColumnIndex() const
Returns an array of type mxINT32_CLASS
representing the column indices (second dimension) of this array.
For sparse arrays, the indices are returned for just the non-zero elements and the size of the array returned is 1-by-NumberOfNonZeros()
.
For nonsparse arrays, the size of the array returned is 1-by-NumberOfElements()
, and the column indices
of all of the elements are returned.
返回阵列元素的列索引;对于稀疏阵列,只返回非零元素的列索引。
void MakeComplex()
Convert a numeric array that has been previously allocated as real
to complex
.
If the underlying array is of a nonnumeric type, an mwException
is thrown.
mwArray Get(mwSize num_indices, ...)
Fetches a single element at a specified index. The index is passed by first passing the number of indices followed by a comma-separated list of 1-based indices. The valid number of indices that can be passed in is either 1 (single subscript indexing), in which
case the element at the specified 1-based offset is returned, accessing data in column-wise order, or NumberOfDimensions()
(multiple
subscript indexing), in which case, the index list is used to access the specified element. The valid range for indices is 1 <= index <= NumberOfElements()
,
for single subscript indexing. For multiple subscript indexing, the i
th index
has the valid range: 1 <= index[i] <= GetDimensions().Get(1, i)
. An mwException
is
thrown if an invalid number of indices is passed in or if any index is out of bounds.
根据索引返回阵列元素,其中num_indices表示索引数目。Get函数中输入的索引均从1起始。
mwArray Get(const char* name, mwSize num_indices, ...)
Fetches a single element at a specified field name and index. This method may only be called on an array that is of type mxSTRUCT_CLASS
.
An mwException
is thrown if the underlying array is not a struct
array.
The field name passed must be a valid field name in the struct
array. The index is passed by first
passing the number of indices followed by a comma-separated list of 1-based indices. The valid number of indices that can be passed in is either 1 (single subscript indexing), in which case the element at the specified 1-based offset is returned, accessing
data in column-wise order, or NumberOfDimensions()
(multiple subscript indexing), in which case, the
index list is used to access the specified element. The valid range for indices is 1 <= index <= NumberOfElements()
,
for single subscript indexing. For multiple subscript indexing, the ith index has the valid range: 1 <= index[i] <= GetDimensions().Get(1,
i)
. AnmwException
is thrown if an invalid number of indices is passed in or if any index is
out of bounds.
返回结构体域名为name,指定索引的结构体域,其中num_indices表示索引的数目。Get函数中输入的索引均从1起始。
mwArray Get(mwSize num_indices, const mwIndex* index)
Fetches a single element at a specified index. The index is passed by first passing the number of indices, followed by an array of 1-based indices. The valid number of indices that can be passed in is either 1 (single subscript indexing), in which case the
element at the specified 1-based offset is returned, accessing data in column-wise order, or NumberOfDimensions()
(multiple
subscript indexing), in which case, the index list is used to access the specified element. The valid range for indices is 1 <= index <= NumberOfElements()
,
for single subscript indexing. For multiple subscript indexing, the ith index has the valid range: 1 <= index[i] <= GetDimensions().Get(1,
i)
. An mwException
is thrown if an invalid number of indices is passed in or if any index is
out of bounds.
mwArray Get(const char* name, mwSize num_indices, const mwIndex* index)
Fetches a single element at a specified field name and index. This method may only be called on an array that is of type mxSTRUCT_CLASS
.
An mwException
is thrown if the underlying array is not a struct
array.
The field name passed must be a valid field name in the struct
array. The index is passed by first
passing the number of indices followed by an array of 1-based indices. The valid number of indices that can be passed in is either 1 (single subscript indexing), in which case the element at the specified 1-based offset is returned, accessing data in column-wise
order, or NumberOfDimensions()
(multiple subscript indexing), in which case, the index list is used
to access the specified element. The valid range for indices is 1 <= index <= NumberOfElements()
,
for single subscript indexing. For multiple subscript indexing, the ith index has the valid range: 1 <= index[i] <= GetDimensions().Get(1,
i)
. An mwException
is thrown if an invalid number of indices is passed in or if any index is
out of bounds.
mwArray Real()
Accesses the real part of a complex array. The returned mwArray
is considered real and has the same
dimensionality and type as the original.
Complex arrays consist of Complex numbers, which are 1 X 2 vectors (pairs). For example, if the number is 3+5i
,
then the pair is (3,5i)
. An array of Complex numbers is therefore two dimensional (N
X 2)
, where N is the number of complex numbers in the array. 2+4i,
7-3i, 8+6i
would be represented as (2,4i) (7,3i) (8,6i)
. Complex numbers have two components,
real and imaginary.
The MATLAB function Real
can be applied to an array of Complex numbers. It extracts the corresponding
part of the Complex number. For example,REAL(3,5i) == 3
.
返回数值阵列的实部
mwArray Imag()
Accesses the imaginary part of a complex array. The returned mwArray
is considered real and has the
same dimensionality and type as the original.
Complex arrays consist of Complex numbers, which are 1 X 2 vectors (pairs). For example, if the number is 3+5i
,
then the pair is (3,5i)
. An array of Complex numbers is therefore two dimensional (N
X 2)
, where N is the number of complex numbers in the array. 2+4i,
7-3i, 8+6i
would be represented as (2,4i) (7,3i) (8,6i)
. Complex numbers have two components,
real and imaginary.
The MATLAB function Imag
can be applied to an array of Complex numbers. It extracts the corresponding
part of the Complex number. For example,IMAG(3+5i) == 5
. Imag
returns 5
in
this case and not 5i
. Imag
returns
the magnitude of the imaginary part of the number as a real number.
返回数值阵列虚部
void Set(const mwArray& arr)
Assign shared copy of input array to currently referenced cell for arrays of type mxCELL_CLASS
and mxSTRUCT_CLASS
.
void GetData(<numeric-type>* buffer, mwSize len) const
Copies the array‘s data into supplied numeric buffer.
The data is copied in column-major order. If the underlying array is not of the same type as the input buffer, the data is converted to this type as it is copied. If a conversion cannot be made, an mwException
is
thrown.
void GetLogicalData(mxLogical* buffer, mwSize len) const
Copies the array‘s data into supplied mxLogical
buffer.
The data is copied in column-major order. If the underlying array is not of type mxLOGICAL_CLASS
, the
data is converted to this type as it is copied. If a conversion cannot be made, an mwException
is
thrown.
void GetCharData(mxChar* buffer, mwSize len) const
Copies the array‘s data into supplied mxChar
buffer.
The data is copied in column-major order. If the underlying array is not of type mxCHAR_CLASS
, the
data is converted to this type as it is copied. If a conversion cannot be made, an mwException
is
thrown.
void SetData(<numeric-type>* buffer, mwSize len) const
Copies the data from supplied numeric buffer into the array.
The data is copied in column-major order. If the underlying array is not of the same type as the input buffer, the data is converted to this type as it is copied. If a conversion cannot be made, an mwException
is
thrown.
void SetLogicalData(mxLogical* buffer, mwSize len) const
Copies the data from the supplied mxLogical
buffer into the array.
The data is copied in column-major order. If the underlying array is not of type mxLOGICAL_CLASS
, the
data is converted to this type as it is copied. If a conversion cannot be made, an mwException
is
thrown.
void SetCharData(mxChar* buffer, mwSize len) const
Copies the data from the supplied mxChar
buffer into the array.
The data is copied in column-major order. If the underlying array is not of type mxCHAR_CLASS
, the
data is converted to this type as it is copied. If a conversion cannot be made, an mwException
is
thrown.
static mwArray Deserialize(const mwArray& arr)
Deserializes an array that has been serialized with mwArray::Serialize()
. The input array must be of
type mxUINT8_CLASS
and contain the data from a serialized array. If the input data does not represent
a serialized mwArray
, the behavior of this method is undefined.
static mwArray NewSparse(mwSize rowindex_size, const mwIndex* rowindex, mwSize colindex_size, const mwIndex* colindex, mwSize data_size, const mxDouble* rData, mwSize num_rows, mwSize num_cols, mwSize nzmax)
Creates real sparse matrix of type double
with specified number of rows and columns.
The lengths of input row, column index, and data arrays must all be the same or equal to 1. In the case where any of these arrays are equal to 1, the value is repeated throughout the construction of the matrix.
If any element of the rowindex
or colindex
array
is greater than the specified values in num_rows
or num_cols
respectively,
an exception is thrown.
This example constructs a sparse 4 X 4 tridiagonal matrix:
The following code, when run:
will display the following output to the screen:
static mwArray NewSparse(mwSize rowindex_size, const mwIndex* rowindex, mwSize colindex_size, const mwIndex* colindex, mwSize data_size, const mxDouble* rdata, mwSize nzmax)
Creates real sparse matrix of type double
with number of rows and columns inferred from input data.
The lengths of input row and column index and data arrays must all be the same or equal to 1. In the case where any of these arrays are equal to 1, the value is repeated through out the construction of the matrix.
The number of rows and columns in the created matrix are calculated form the input rowindex
and colindex
arrays
as num_rows = max{rowindex}, num_cols = max{colindex}
.
In this example, we construct a sparse 4 X 4 identity matrix. The value of 1.0 is copied to each non-zero element defined by row and column index arrays:
static mwArray NewSparse(mwSize rowindex_size, const mwIndex* rowindex, mwSize colindex_size, const mwIndex* colindex, mwSize data_size, const mxDouble* rdata, const mxDouble* idata, mwSize num_rows, mwSize num_cols, mwSize nzmax)
Creates complex sparse matrix of type double
with specified number of rows and columns.
The lengths of input row and column index and data arrays must all be the same or equal to 1. In the case where any of these arrays are equal to 1, the value is repeated through out the construction of the matrix.
If any element of the rowindex
or colindex
array
is greater than the specified values in num_rows
, num_cols
,
respectively, then an exception is thrown.
This example constructs a complex tridiagonal matrix:
static mwArray NewSparse(mwSize rowindex_size, const mwIndex* rowindex, mwSize colindex_size, const mwIndex* colindex, mwSize data_size, const mxDouble* rdata, const mxDouble* idata, mwSize nzmax)
Creates complex sparse matrix of type double
with number of rows and columns inferred from input data.
The lengths of input row and column index and data arrays must all be the same or equal to 1. In the case where any of these arrays are equal to 1, the value is repeated through out the construction of the matrix.
The number of rows and columns in the created matrix are calculated form the input rowindex
and colindex
arrays
as num_rows = max{rowindex}, num_cols = max{colindex}
.
This example constructs a complex matrix by inferring dimensions and storage allocation from the input data.
static mwArray NewSparse(mwSize rowindex_size, const mwIndex* rowindex, mwSize colindex_size, const mwIndex* colindex, mwSize data_size, const mxLogical* rdata, mwSize num_rows, mwSize num_cols, mwSize nzmax)
Creates logical sparse matrix with specified number of rows and columns.
The lengths of input row and column index and data arrays must all be the same or equal to 1. In the case where any of these arrays are equal to 1, the value is repeated throughout the construction of the matrix.
If any element of the rowindex
or colindex
array
is greater than the specified values in num_rows
, num_cols
,
respectively, then an exception is thrown.
This example creates a sparse logical 4 X 4 tridiagonal matrix, assigning true
to each non-zero value:
static mwArray NewSparse(mwSize rowindex_size, const mwIndex* rowindex, mwSize colindex_size, const mwIndex* colindex, mwSize data_size, const mxLogical* rdata, mwSize nzmax)
Creates logical sparse matrix with number of rows and columns inferred from input data.
The lengths of input row and column index and data arrays must all be the same or equal to 1. In the case where any of these arrays are equal to 1, the value is repeated through out the construction of the matrix.
The number of rows and columns in the created matrix are calculated form the input rowindex
and colindex
arrays
as num_rows = max {rowindex}, num_cols = max {colindex}
.
This example uses the data from the first example, but allows the number of rows, number of columns, and allocated storage to be calculated from the input data:
static mwArray NewSparse (mwSize num_rows, mwSize num_cols, mwSize nzmax, mxClassID mxID, mxComplexity cmplx = mxREAL)
Creates an empty sparse matrix. All elements in an empty sparse matrix are initially zero, and the amount of allocated storage for non-zero elements is specified by nzmax
.
This example constructs a real 3 X 3 empty sparse matrix of type double
with reserved storage for 4
non-zero elements:
static double GetNaN()
Get value of NaN
(Not-a-Number).
Call mwArray::GetNaN
to return the value of NaN
for
your system. NaN
is the IEEE arithmetic representation for Not-a-Number. Certain mathematical operations
return NaN
as a result, for example:
0.0/0.0
Inf-Inf
The value of NaN
is built in to the system; you cannot modify it.
static double GetEps()
Returns the value of the MATLAB eps
variable. This variable is the distance from 1.0 to the next largest
floating-point number. Consequently, it is a measure of floating-point accuracy. The MATLAB pinv
and rank
functions
use eps
as a default tolerance.
static double GetInf()
Returns the value of the MATLAB internal Inf
variable. Inf
is
a permanent variable representing IEEE arithmetic positive infinity. The value of Inf
is built into
the system; you cannot modify it.
Operations that return Inf
include
Division by 0. For example, 5/0 returns Inf
.
Operations resulting in overflow. For example, exp(10000)
returns Inf
because
the result is too large to be represented on your machine.
static bool IsFinite(double x)
Determine whether or not a value is finite. A number is finite if it is greater than -Inf
and less
than Inf
.
static bool IsInf(double x)
Determines whether or not a value is equal to infinity or minus infinity. MATLAB stores the value of infinity in a permanent variable named Inf
,
which represents IEEE arithmetic positive infinity. The value of the variable, Inf
, is built into
the system; you cannot modify it.
Operations that return infinity include
Division by 0. For example, 5/0 returns infinity.
Operations resulting in overflow. For example, exp(10000)
returns infinity because the result is too
large to be represented on your machine. If the value equals NaN
(Not-a-Number), then mxIsInf
returns false
.
In other words, NaN
is not equal to infinity.
static bool IsNaN(double x)
Determines whether or not the value is NaN
. NaN
is
the IEEE arithmetic representation for Not-a-Number. NaN
is obtained as a result of mathematically
undefined operations such as
0.0/0.0
Inf-Inf
The system understands a family of bit patterns as representing NaN
. In other words, NaN
is
not a single value, rather it is a family of numbers that the MATLAB software (and other IEEE-compliant applications) use to represent an error condition or missing data.
mwArray operator()(mwIndex i1, mwIndex i2, mwIndex i3, ..., )
Fetches a single element at a specified index. The index is passed as a comma-separated list of 1-based indices. This operator is overloaded to support 1 through 32 indices. The valid number of indices that can be passed in is either 1 (single subscript indexing),
in which case the element at the specified 1-based offset is returned, accessing data in column-wise order, or NumberOfDimensions()
(multiple
subscript indexing), in which case, the index list is used to access the specified element. The valid range for indices is 1 <= index <= NumberOfElements()
,
for single subscript indexing. For multiple subscript indexing, the ith index has the valid range: 1 <= index[i] <= GetDimensions().Get(1,
i)
. An mwException
is thrown if an invalid number of indices is passed in or if any index is
out of bounds.
mwArray operator()(const char* name, mwIndex i1, mwIndex i2, mwIndex i3, ..., )
Fetches a single element at a specified field name and index. This method may only be called on an array that is of type mxSTRUCT_CLASS
.
An mwException
is thrown if the underlying array is not a struct
array.
The field name passed must be a valid field name in the struct
array. The index is passed by first
passing the number of indices, followed by an array of 1-based indices. This operator is overloaded to support 1 through 32 indices. The valid number of indices that can be passed in is either 1 (single subscript indexing), in which case the element at the
specified 1-based offset is returned, accessing data in column-wise order, or NumberOfDimensions()
(multiple
subscript indexing), in which case, the index list is used to access the specified element. The valid range for indices is 1 <= index <= NumberOfElements()
,
for single subscript indexing. For multiple subscript indexing, the ith index has the valid range:1 <= index[i] <= GetDimensions().Get(1,
i)
. An mwException
is thrown if an invalid number of indices is passed in or if any index is
out of bounds.
mwArray& operator=(const <type>& x)
Sets a single scalar value. This operator is overloaded for all numeric and logical types.
operator <type>() const
Fetches a single scalar value. This operator is overloaded for all numeric and logical types.
[Matlab] MxArray 与 MwArray 使用区别
标签:
原文地址:http://blog.csdn.net/fonjames/article/details/51622151