How to identify the input and output in a c code generated from Simulink model
    10 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Vivek Anantharaman
 am 28 Jan. 2020
  
    
    
    
    
    Beantwortet: Vivek Anantharaman
 am 10 Feb. 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 Kommentare
Akzeptierte Antwort
  Divya Yerraguntla
    
 am 6 Feb. 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 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
				Mehr zu Simulink Coder finden Sie in Help Center und File Exchange
			
	Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

