%% Load and Save Parts of Variables
% Access specific parts of a variable in a MAT-file using the MAT-file object. For example, you can save data to a subset of a variable in a MAT-file or read a subset of a variable into the MATLAB® workspace.
%
% Save data to a subset of a variable y in the file  myFile2.mat using the MAT-file object. First, create the MAT-file object m.

m = matfile('myFile2.mat');

% Next, create and save an array to part of the variable y. Specify the variable in the MAT-file using dot notation similar to accessing fields of structure arrays. MATLAB® inserts the 20-by-20 array into the elements of y specified by the indices (81:100,81:100).

m.y(81:100,81:100) = magic(20);

%
% Read a subset of array y into a new workspace variable, z. MATLAB® reads the 10-by-10 subarray specified by the indices (85:94,85:94) from the MAT-file into workspace variable z.

z = m.y(85:94,85:94);

% Copyright 2012 The MathWorks, Inc.