How to identify the input and output in a c code generated from Simulink model
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Vivek Anantharaman
el 28 de En. de 2020
Respondida: Vivek Anantharaman
el 10 de Feb. de 2020
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 comentarios
Respuesta aceptada
Divya Yerraguntla
el 6 de Feb. de 2020
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 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre Simulink Coder en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!