查找一个使用mxGetCell函数的C语言代码示例
时间: 2023-03-27 20:05:00 浏览: 77
以下是一个使用mxGetCell函数的C语言代码示例:
```
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mxArray *cell_array_ptr;
double *data_ptr;
int i, j, num_rows, num_cols;
/* Check for proper number of input and output arguments */
if (nrhs != 1)
mexErrMsgTxt("One input argument required.");
if (nlhs > 1)
mexErrMsgTxt("Too many output arguments.");
/* Check that input argument is a cell array */
if (!mxIsCell(prhs[]))
mexErrMsgTxt("Input argument must be a cell array.");
/* Get dimensions of cell array */
num_rows = mxGetM(prhs[]);
num_cols = mxGetN(prhs[]);
/* Loop over each element of cell array */
for (i = ; i < num_rows; i++)
{
for (j = ; j < num_cols; j++)
{
/* Get pointer to current cell */
cell_array_ptr = mxGetCell(prhs[], i + j*num_rows);
/* Check that current cell contains a double array */
if (!mxIsDouble(cell_array_ptr) || mxIsComplex(cell_array_ptr))
mexErrMsgTxt("Cell array must contain only real double arrays.");
/* Get pointer to data in current cell */
data_ptr = mxGetPr(cell_array_ptr);
/* Do something with data in current cell */
/* ... */
}
}
}
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)