%% Save Entire Variable to Existing MAT-file
% Create a MAT-file containing an array and then add another array to the file using the MAT-file object.
%
% Create a MAT file by generating a 20-by-20 array, x, and saving it to myFile.mat.

x = magic(20);
save('myFile.mat','x');

% Create a MAT-file object connected to the existing MAT-file. Enable write access by setting Writable to true.

m = matfile('myFile.mat','Writable',true);

%
% Generate another 15-by-15 array, y. Save y to the MAT-file using the MAT-file object. Specify the variable in the MAT-file using dot notation similar to accessing fields of structure arrays. MATLAB® adds a variable named y to the file.

y = magic(15);
m.y = y;

%
% Display all variables stored in the MAT-file, myFile.mat.

whos('-file','myFile.mat')

% Copyright 2012 The MathWorks, Inc.