Call questdlg from C S-Function

2 Ansichten (letzte 30 Tage)
Allen Peacock
Allen Peacock am 28 Jan. 2014
Kommentiert: Allen Peacock am 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 Kommentar
Allen Peacock
Allen Peacock am 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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Kaustubha Govind
Kaustubha Govind am 31 Mär. 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 Kommentar
Allen Peacock
Allen Peacock am 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?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Write C Functions Callable from MATLAB (MEX Files) finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by