Call questdlg from C S-Function

2 visualizaciones (últimos 30 días)
Allen Peacock
Allen Peacock el 28 de En. de 2014
Comentada: Allen Peacock el 14 de Abr. de 2014
Hello, Is it possible to call questdlg(...) from within a simple C S-Function AND get the resulting answer? Please provide an example. Thank You
  1 comentario
Allen Peacock
Allen Peacock el 14 de Abr. de 2014
Hello and thanks for the quick response. I have followed your reference and this is what I produced:
#include "mex.h"
void
mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mxArray *lhs[1];
char sArray[15] = "Are you sure?";
(void) prhs; /* unused parameter */
/* Check for proper number of input and output arguments */
if (nrhs != 0) {
mexErrMsgTxt("No input arguments required.");
}
if(nlhs > 1){
mexErrMsgTxt("Too many output arguments.");
}
/* Display a question dialog & get response */
mexCallMATLAB(1, lhs, 1, sArray, "questdlg");
}
It mex's without error. Unfortunately I get a Stack Dump/Trace when calling it. Not sure why it fails. Can you help?

Iniciar sesión para comentar.

Respuesta aceptada

A Jenkins
A Jenkins el 14 de Abr. de 2014
You can use mxCreateString to hold your string value.
#include "mex.h"
void
mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mxArray *lhs[1];
mxArray *pArray;
const char sArray[] = "Are you sure?";
/* Check for proper number of input and output arguments */
if (nrhs != 0) {
mexErrMsgTxt("No input arguments required.");
}
if(nlhs > 1){
mexErrMsgTxt("Too many output arguments.");
}
/* Create a string array. */
pArray = mxCreateString(sArray);
/* Display a question dialog & get response */
mexCallMATLAB(1, lhs, 1, &pArray, "questdlg");
/* Write the output back to MATLAB */
plhs[0] = lhs[0];
/* When finished with the string array, free its memory. */
mxDestroyArray(pArray);
}
  1 comentario
Allen Peacock
Allen Peacock el 14 de Abr. de 2014
Perfect! It worked like a charm. Thanks A Jenkins.

Iniciar sesión para comentar.

Más respuestas (1)

Kaustubha Govind
Kaustubha Govind el 31 de Mzo. de 2014
Yes, you can use mexCallMATLAB to call MATLAB functions from a C-MEX S-function. Please refer to the examples in the documentation.
  1 comentario
Allen Peacock
Allen Peacock el 14 de Abr. de 2014
Sorry, I may have put my response/question in the wrong spot. Here it is again: Hello and thanks for the quick response. I have followed your reference and this is what I produced:
#include "mex.h"
void
mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mxArray *lhs[1];
char sArray[15] = "Are you sure?";
(void) prhs; /* unused parameter */
/* Check for proper number of input and output arguments */
if (nrhs != 0) {
mexErrMsgTxt("No input arguments required.");
}
if(nlhs > 1){
mexErrMsgTxt("Too many output arguments.");
}
/* Display a question dialog & get response */
mexCallMATLAB(1, lhs, 1, sArray, "questdlg");
}
It mex's without error. Unfortunately I get a Stack Dump/Trace when calling it. Not sure why it fails. Can you help?

Iniciar sesión para comentar.

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