How do I import a MAT file with a table for use inside of a custom mask with a MATLAB function block?
MATLAB: Import tables in MAT files in custom Mask for use with ML Function Block
blockfilefunctionimportmaskmatMATLABsimulinktable
Related Question
- How do you find and replace rows in two tables with some variables in common
- How to store user data into a Simulink block
- How do you order table columns based on a vector with their names
- How to set parameters in the MATLAB Function block in Simulink
- Error with “timetable” when using the same “VariableNames” argument as for successful use of “table”
- How to use a Simulink.Signal Object as a parameter in a masked subsystem in R2017a
- Does the ‘CellEditCallback’ not get fired when a uitable has a table variable as its ‘Data’ on MATLAB R2018a
- Are Simulink.Signal objects’ Max and Min not enforced in the generated code
Best Answer
For variables to be accessed through the mask, they need to be Simulink parameters. As you cannot have a "table" type in a Simulink parameter, the closest method is to convert your table into a "struct".
A "struct" will not include your row names, but will still include the column names.
To do this, create a mask over your MATLAB Function block.
The mask should have an "edit" parameter to specify the table object you are working with. You would also most likely want a "button" action to allow for a "uigetfile" callback to have a user select a file, then load the table as a mask parameter.
The "edit" parameter needs to hold the table value. On the mask initialization callback, set a variable using the "table2struct" function on your table parameter.
In the MATLAB function block, select Simulink from the top ribbon, then "Edit Data". Add a parameter with the same name as the mask structure parameter. You should now have access to a structure in the MATLAB function block.