How can you save variables to a file in Matlab?
You can use the save function to store variables in a file. Here are some examples:
- Save a single variable to a file.
x = 1:10;
save('filename.mat', 'x');
This will save the variable x to a MAT file named filename.mat.
- Save multiple variables to a file.
x = 1:10;
y = rand(1, 10);
save('filename.mat', 'x', 'y');
This will save variables x and y to a MAT file named filename.mat.
- Save all variables to a file.
save('filename.mat');
This will save all variables in the current workspace to a MAT file named filename.mat.
Please note that MAT files can be loaded back into the MATLAB workspace using the load function.