9.6) Reading And Writing *.MAT Files
- The "mat" file is the native file format for storing data. It is a sophisticated binary file format, that offers fast saving and loading, as well as fairly efficient use of storage
- Given that it is heavily supported within Matlab, it is the preferred storage file format for working with data within Matlab. It is a propriety file format and so is not readily readable by other programs
- We can save the entire workspace:
- Or just save specific variables:
- And we can add data (append) to an existing "mat" file
- And importantly, we can load data from a "mat" file:
[matlab]
>> A=randn(20,2);
>> B=rand(100,100);
>> save('workspace.mat')
[/matlab]
[matlab]
>> save('random_data.mat', 'A');
[/matlab]
[matlab]
>> save('random_data.mat', 'B', '-append');
[/matlab]
[matlab]
>> load('workspace.mat')
[/matlab]
Or just load specific variables from a "mat" file into the current workspace
[matlab]
>> load('workspace.mat', 'A');
[/matlab]