Pointer to Simulink Function
10 次查看(过去 30 天)
显示 更早的评论
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!