How to initialize variable parameter from excel file in place of initialization .m file in Simulink.
Show older comments
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?
Answers (2)
Ameer Hamza
on 21 Apr 2018
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
on 1 Dec 2020
0 votes
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
Categories
Find more on Event Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!