Main Content

Load constants from a MAT-File

You can load compile-time constants from a MAT-file with the coder.load function in your MATLAB design.

For example, you can create a MAT-file, sinvals.mat, that contains fixed-point values of sin by entering the following commands in MATLAB:

sinvals = sin(fi(-pi:0.1:pi, 1, 16,15));
save sinvals.mat sinvals;

You can then generate HDL code from the following MATLAB® code, which loads the constants from sinvals.mat into a persistent variable, pConstStruct, and assigns the values to a variable that is not persistent, sv.

persistent pConstStruct;
if isempty(pConstStruct)
    pConstStruct = coder.load('sinvals.mat');
end
sv = pConstStruct.sinvals;

See Also

|

Related Topics