Simulink - control flow using custom C code
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to generate a Simulink model which when generated code, exhibits a functionality like this:
if (rollDice()==7) {
// Do something (anything)
if (rollDice()==7) {
// Do something (anything)
}
}
Now the function rollDice() is my custom C function, I want to provide it somehow. I do not want to model this using s-functions, I want to model this using Simulink blocks; only the rollDice() function is my custom C code.
This is my attempt: I provided the rollDice() function using Model Configuration Parameters > Code Generation > Custom code > Source File.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162336/image.png)
Then I tried to use an `If Block` and put the rollDice() code directly in the field of If Expression. However, that is not allowed (Simulink throws an error message).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/162337/image.png)
Please help by suggesting whether it is possible to model this behavior using Simulink blocks! My ultimate goal is to generate code which looks like the code I posted on the top of my question.
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Simulink Coder 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!