How to identify the input and output in a c code generated from Simulink model
9 次查看(过去 30 天)
显示 更早的评论
With the help of the simulink coder, I could genrate a c code for my simulink model.
Now, I want to know how and where to find the inputs and outputs presen in the c code, so that a cusomized inputs can be passed to the model.
Please let me know if any additional information is required.
0 个评论
采纳的回答
Divya Yerraguntla
2020-2-6
Hi Vivek,
In order to provide customized inputs you need to change the input source blocks used in the model during simulation to Inports(say In1, In2 etc.) and then generate the code. Now when you look at the generated (model_name).c file you will be able to find the void (model_name)_step(void) function which is called at every time step and contains the main dynamics of the model. This is the function where you can read inputs from external sources at every time step and produce output.
In the (model_name).c you will notice input variables as test_U.In1, test_U.In2 etc. We can read inputs and display outputs in this function as shown below:
scanf("%lf %lf",&(test_U.In1),&(test_U.In2)); %% lf for double datatype
printf("Input: %lf %lf\n",test_U.In1,test_U.In2);
%% Model Dynamics(computations on test_U.In1,test_U.In2)
printf("Ouput: %lf\n",test_Y.Out1);
Now on compiling, buidling and finally running the executable it will prompt you to provide input for all the time steps in one go and once you give that, you will see the output as well.
Hope it helps!
0 个评论
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!