C-MEX file: I want to return an empty array, does anyone know how?

8 visualizaciones (últimos 30 días)
If I assign plhs[0] = NULL; I get a warning in Matlab's command window and the output argument is not created/modified. Any attempt to create a matrix or an array with 0's dimensions causes Matlab to crash.

Respuesta aceptada

James Tursa
James Tursa el 19 de Ag. de 2015
This will return an empty 0x0 matrix:
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
plhs[0] = mxCreateDoubleMatrix( 0, 0, mxREAL );
}
If you need something else please provide more detail about what you are trying to do.

Más respuestas (1)

Vincent Huber
Vincent Huber el 2 de Oct. de 2020
In C++ if I call for
value = feval(mh,"myMexfunction",arg1,...)
with inside
outputs[0] = factory.createArray<double>({ 0,0 });
Matlab complains the following way:
Error using matlab.mex.MexHost/feval
Too many output arguments.

Categorías

Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by