Custom C Code question: How do set extern variables from simulink model
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have a simple C code file that has four extern variables (three inputs, one output)
main.c:
#include <math.h>
#include "main.h"
extern float A1;
extern float A2;
extern float A3;
extern float OUTPUT;
void do_something(void) {
OUTPUT = cos(A1) * sin(A2) * cos(A3);
}
main.h:
void do_something(void);
I wish to add this C code to my stateflow model and output the variable OUTPUT
This is how I currently have my custom c code setting
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/219236/image.png)
The 'include directories' sections only has a '.' so that every file in included (currently only main.h). And the 'source file' section is empty
My models are setup like this
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/219237/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/219238/image.png)
I can the following error:
![Capture.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/219239/Capture.png)
5 Kommentare
James Tursa
am 13 Mai 2019
Bearbeitet: James Tursa
am 13 Mai 2019
"I don't want to define these variables using another .c file"
But that is specifically what the extern keyword does ... it instructs the compiler that these variables are defined in another file. All variables in your code have to be defined somewhere. You might have Stateflow specific code for setting these variables to values, but the variables still must be defined somewhere.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Stateflow 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!