Defining Model Settings Using External Data File
To use tabulated data from files in a model, use the interpolation function available under the Global Definitions node or the Definitions node of the model.
To add an interpolation function under the Global Definitions node, enter:
model.func.create(<functag>, 'Interpolation')
If you have several model nodes in your model and you want to attach it to the specified component node <ctag>, enter:
model.component(<ctag>).func.create(<functag>, 'Interpolation')
where <ctag> is the tag of the model node to attach the interpolation function.
Then you can interpolate data specified by a table inside the function (default), or specified in an external file.
When using an interpolation table, set the interpolation data for each row of the table with the commands:
func.setIndex('table', <t_value>, <i>, 1)
func.setIndex('table', <ft_value>, <i>, 2)
where func is a link to a function node and <t_value> is the interpolation parameter value and <ft_value> is the function value. <i> is the index (0-based) in the interpolation table. If the number of rows is large then it takes a long time to create the table element by element. Instead store all the data as a cell array of strings and set the values all at once:
func.set('table', data)
To use an external file change the source for the interpolation and specify the file, where filename is the name (including the path) of the data file:
func.set('source', 'file')
func.set('filename', <filename>)
Several interpolation methods are available. Choose the one to use with the command:
func.set('interp', method)
The string method can be set as one of the following alternatives:
'neighbor', for interpolation according to the nearest neighbor method,
'linear', for linear interpolation method,
'cubicspline', for cubic spline interpolation method, or
'piecewisecubic', piecewise cubic interpolation method.
You can also decide how to handle parameter values outside the range of the input data by selecting an extrapolation method:
func.set('extrap', method)
The string method can be one of these values:
'const', to use a constant value outside the interpolation data,
'linear', for linear extrapolation method,
'nearestfunction', to use the nearest function as extrapolation method, or
'value', to use a specific value outside the interpolation data.
model.func() in the COMSOL Multiphysics Programming Reference Manual or type at the MATLAB prompt: mphdoc(model.func).