How to initialize variable parameter from excel file in place of initialization .m file in Simulink.

조회 수: 1 (최근 30일)
How to initialize variable parameter from excel file in place of initialization .m file in Simulink. Currently in my Simulink model I initialize variable parameters for the model via .m file. I want to use the excel file inplace How to do it? For example: Currently I have following variables ChamberPressure=148; ChamberTemp=156; outFlow=22; inflow=23; ChamberVolume=39 ChamberDia=23 ChamberHeight=100 BurstPressure=150 I already have an excel file configured as above with file name as “InitPara.xls” where variables are under column-A, Values on Column-B and Unit under Column-C
How to use this “InitPara.xls” excel file in place of .m file currently I have in Matlab-Simulink?

답변 (2개)

Ameer Hamza
Ameer Hamza 2018년 4월 21일

You can use xlsread to read vales from the xls file.

file = 'filename';
sheet = 1;
range = 'B2:B9';
[~, ~, data] = xlsread(file, sheet, range);
data = [data{:}];

Then you can use these values however you want. For example, you can assign these values to the variable name of your choice.

ChamberPressure = data(1);
ChamberTemp = data(2);
. . .
. . .
BurstPressure = data(8);

Or you can directly use data(1), data(2), etc. in your model.


Ting Liang
Ting Liang 2020년 12월 1일
Hi, Ameer,
Excuse me.
Can I ask whether it is possible to set up a M file(M code) to achieve parameter initialization? Cause if I use InitFcn to initialize the parameters, they cannot be annotated, some time later, it would be difficult for me to recognize these parameters?
Thanks.
Best regards

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by