readparam
Small function to read a list of parameters for a model and return it in a structure, so
it's easy to handle as a unit. I use it quite a bit in my own work. Thought it could be useful for
others.
S= readparam(filename) reads a list of parameter names and values
from a file, either a comma-separated file (csv) or an Excel file (xls).
'filename' is a string with the name of the file. The values are
returned in structure S, with the names of the parameters as field
names. The value of parameter 'par' can be accessed as 'S.par'.
Parameter values can be: scalars, vectors, character strings or function
handlers. Specify vectors with square brackets and separate
the values with spaces (NOT commas). To indicate a character
string put a '#' before the string, just after the comma.
To identify a function handle put a '@' before the function's name.
Parameter names have to be in the first column and the values in the
second column. The first row of the file is not returned, but it cannot
be empty. If the data are in Excel the data has to be in the
first sheet of the file.
P= readparam('readparam.csv')
In the example included, "time", "tstep", "area", "verbose" and
"savesim" are scalars. "temp" is a vector of three values
(do NOT separate the values with commas). "P.odesol" is a function
handle for one of Matlab's ODE solvers. "P.repmod" is a
character string to define some choice within your model.
"P.spcfile" is the name of a file where additional info is stored.
Cite As
Francisco de Castro (2024). readparam (https://www.mathworks.com/matlabcentral/fileexchange/69446-readparam), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.