Call M-script in C/C++ Sfunction
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Andreas
el 10 de Feb. de 2017
Respondida: Sonam Gupta
el 14 de Feb. de 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
0 comentarios
Respuesta aceptada
Sonam Gupta
el 14 de Feb. de 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.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Block and Blockset Authoring en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!