Call questdlg from C S-Function

10 ビュー (過去 30 日間)
Allen Peacock
Allen Peacock 2014 年 1 月 28 日
コメント済み: Allen Peacock 2014 年 4 月 14 日
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 件のコメント
Allen Peacock
Allen Peacock 2014 年 4 月 14 日
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?

サインインしてコメントする。

採用された回答

A Jenkins
A Jenkins 2014 年 4 月 14 日
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 件のコメント
Allen Peacock
Allen Peacock 2014 年 4 月 14 日
Perfect! It worked like a charm. Thanks A Jenkins.

サインインしてコメントする。

その他の回答 (1 件)

Kaustubha Govind
Kaustubha Govind 2014 年 3 月 31 日
Yes, you can use mexCallMATLAB to call MATLAB functions from a C-MEX S-function. Please refer to the examples in the documentation.
  1 件のコメント
Allen Peacock
Allen Peacock 2014 年 4 月 14 日
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?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by