Filter löschen
Filter löschen

Call M-script in C/C++ Sfunction

2 Ansichten (letzte 30 Tage)
Andreas
Andreas am 10 Feb. 2017
Beantwortet: Sonam Gupta am 14 Feb. 2017
I have a S-Function written in C. I want to call a m-script during from this S-Function. How is this possible?
Thanke

Akzeptierte Antwort

Sonam Gupta
Sonam Gupta am 14 Feb. 2017
I understand that you have written a S-Function in C and you want to call a matlab script from that function. I assume that you are using MATLAB R2016b.
You can do the above by using 'mexEvalString('Name_of_Script')' function in mdlOutputs method of S-Function. To illustrate, I am using timestwo example available at the following link http://in.mathworks.com/help/simulink/sfg/example-of-a-basic-c-mex-s-function.html and a dummy script plotline.m which plots a line. I am calling this MATLAB Script from timestwo S-function.
plotLine.m looks as below:
x = [1 2 3];
y = [1 2 3];
plot(x,y);
mdlOutputs method in timestwo.c looks as below:
static void mdlOutputs(SimStruct *S, int_T tid)
{
int_T i;
InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0);
real_T *y = ssGetOutputPortRealSignal(S,0);
int_T width = ssGetOutputPortWidth(S,0);
for (i=0; i<width; i++) {
*y++ = 2.0 *(*uPtrs[i]);
}
mexEvalString("plotLine");
}
Now use mex timestwo.c to compile this S-Function. Run the S-function and notice that it also executes the script now.
I hope that this helps.

Weitere Antworten (0)

Kategorien

Mehr zu Block and Blockset Authoring finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by