How to pass inputs from excel to an inport using just code

조회 수: 3 (최근 30일)
Harish
Harish 2023년 7월 25일
댓글: Harish 2023년 7월 28일
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?

채택된 답변

Harald
Harald 2023년 7월 25일
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
Harald
Harald 2023년 7월 28일
편집: Harald 2023년 7월 28일
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:
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
Harish
Harish 2023년 7월 28일
Thankyou for the solution. This helped me and it works now.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Functions에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by