If you want to generate a code to recreate a variable, then try following ways
matlab.io.saveVariablesToScript(fileName, variableName);
filename and variable are both char arrays.
- Right-click the variable in the Workspace window and click Save As. Then select m-file as target file option.
After creating these files, you can use the generated code to recreate variables with same values. However, this will only work for variables of small size. You can configure the maximum size of the variable from Preferences > Workspace.
Best Answer