Pointer to Simulink Function
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Suppose I have a custom C function that accepts a function pointer as an argument,
float cFunc(float val, float (*ptrFunc)(float)) {
return ptrFunc(val);
}
and within Simulink, I defined a Simulink Function called "slxFunc" that takes a float as an input and outputs a float.
How do I obtain the pointer to slxFunc so that I could feed it to cFunc using a C-caller block?
Much appreciated, thanks.
/* edit 1: extra info */
The following C code is what I am trying to emulate,
#include <stdio.h>
/* times2 should be defined in simulink */
float times2(float val) {
return (2.0*val);
}
/* times3 should also be defined in simulink */
float times3(float val) {
return (3.0*val);
}
/* myFunc is defined in a .c file */
float myFunc(float val, float (*slxFunc)(float)) {
return (slxFunc(val));
}
int main()
{
/* printf should print 4.0 6.0 */
printf("%f\t%f\n", myFunc(2.0, times2), myFunc(2.0, times3));
return 0;
}
, where
times2
and
times3
are to be defined in the Simulink environment, and
myFunc
is implemented as a custom C function.
2 Kommentare
Siehe auch
Kategorien
Mehr zu Simulink Functions 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!