How to pass inputs from excel to an inport using just code
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
I want to send inputs from an excel file to an inport of a simulink model. I also want to run it using 'sim' command. Any ideas on this?
0 Kommentare
Akzeptierte Antwort
Harald
am 25 Jul. 2023
Hi Harish,
when you use inports, you will typically set something like [t, u] as inputs, so I suppose what you want to do is define t and u or whatever you call these variables from a spreadsheet? In that case, I would perform steps like importing the spreadsheet and extracting t and u from this in a model callback, see https://www.mathworks.com/help/simulink/ug/model-callbacks.html.
Best wishes,
Harald
7 Kommentare
Harald
am 28 Jul. 2023
Bearbeitet: Harald
am 28 Jul. 2023
Hi Harish,
the code looks good to me.
You will need to adjust the model to let the Inport block know that it should be using that inputPort variable. In the Model Explorer, open a configuration and navigate to the Data Import / Export tab and edit Input. Just to give an example:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1444297/image.png)
In real life, you would specify Input as a matrix with (# Input blocks + 1) many columns: first column is time, the other columns each correspond to one Input block.
You can then extract the simulation results from out, e.g. look at
out(1).yout{1}.Values.Data
Best wishes,
Harald
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Manual Performance Optimization 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!