User`s manual

2 Creating C Language MEX-Files
2-26
data types in MATLAB, arrays can be passed into and out of MEX-files written
in C. You can manipulate multidimensional numerical arrays by using
mxGetData and mxGetImagData to return pointers to the real and imaginary
parts of the data stored in the original multidimensional array.
This example takes an N-dimensional array of doubles and returns the indices
for the nonzero elements in the array.
/*=============================================================
* findnz.c
* Example for illustrating how to handle N-dimensional arrays in
* a MEX-file. NOTE: MATLAB uses 1-based indexing, C uses 0-based
* indexing.
*
* Takes an N-dimensional array of doubles and returns the indices
* for the non-zero elements in the array. findnz works
* differently than the FIND command in MATLAB in that it returns
* all the indices in one output variable, where the column
* element contains the index for that dimension.
*
*
* This is a MEX-file for MATLAB.
* Copyright (c) 1984-2000 by The MathWorks, Inc.
*
*============================================================*/
/* $Revision: 1.5 $ */
#include "mex.h"
/* If you are using a compiler that equates NaN to zero, you must
* compile this example using the flag -DNAN_EQUALS_ZERO. For
* example:
*
* mex -DNAN_EQUALS_ZERO findnz.c
*
* This will correctly define the IsNonZero macro for your
compiler. */
#if NAN_EQUALS_ZERO
#define IsNonZero(d) ((d) != 0.0 || mxIsNaN(d))
#else