Hello Aj,
I noticed that you're encountering the warning: "The variables that could not be saved into MATLAB Script are saved into MAT file" while trying to save your workspace variables to a MATLAB script file.
This warning appears because some of the variables in your workspace cannot be represented as MATLAB code within a script file. To understand this better, you need to know differences between a MAT file and a MATLAB script file.
Script files are meant to be executed. When you load a script file, MATLAB runs the commands in the file to recreate the variables.
- Certain types of variables such as MATLAB objects, function handles, and anonymous functions cannot be saved into a script file and are instead stored in a MAT-file.
- MATLAB provides the 'matlab.io.saveVariablesToScript' function to save workspace variables to a script file. However, it has limitations on what can be saved to a script.
MAT files are optimized for storing and retrieving data. They handle large datasets and complex structures efficiently, which a text-based script cannot. Loading a MAT file is typically faster and more reliable than executing a script to recreate the same variables.
If you use the MATLAB Editor's "Save Workspace As" feature and select "MATLAB Script," MATLAB will attempt to generate a script file that recreates these variables. However, if some variables cannot be converted to code, MATLAB will:
- Generate a Script File: For variables that can be represented as MATLAB code, MATLAB will create a script file (e.g., workspace_script.m).
- Save to a MAT File: For variables that cannot be converted to code, MATLAB will save them into a MAT file (e.g., workspace_script.mat) and issue a warning.
you can refer to the following MathWorks Documentation to understand more
Hope the above information helps you