Effacer les filtres
Effacer les filtres

Call M-script in C/C++ Sfunction

4 vues (au cours des 30 derniers jours)
Andreas
Andreas le 10 Fév 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

Réponse acceptée

Sonam Gupta
Sonam Gupta le 14 Fév 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.

Plus de réponses (0)

Catégories

En savoir plus sur Block and Blockset Authoring dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by