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