Call questdlg from C S-Function

2 visualizzazioni (ultimi 30 giorni)
Allen Peacock
Allen Peacock il 28 Gen 2014
Commentato: Allen Peacock il 14 Apr 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 Commento
Allen Peacock
Allen Peacock il 14 Apr 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?

Accedi per commentare.

Risposta accettata

A Jenkins
A Jenkins il 14 Apr 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 Commento
Allen Peacock
Allen Peacock il 14 Apr 2014
Perfect! It worked like a charm. Thanks A Jenkins.

Accedi per commentare.

Più risposte (1)

Kaustubha Govind
Kaustubha Govind il 31 Mar 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 Commento
Allen Peacock
Allen Peacock il 14 Apr 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?

Accedi per commentare.

Categorie

Scopri di più su Write C Functions Callable from MATLAB (MEX Files) in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by