How to identify the input and output in a c code generated from Simulink model
조회 수: 5 (최근 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!