%% Write Data Into a MAT File
% Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent step syntax. For example, myObject(x) becomes step(myObject,x).
% First, create a variable name.

filename = [tempname '.mat'];

%
% Next, write that variable to a MAT-file.

mfw = dsp.MatFileWriter(filename,'VariableName','originalData');
for i = 1:10
    originalData = rand(4,2);
    mfw(originalData);
end
release(mfw); % This will close the MAT file

%
% Finally, load the variable back into MATLAB.

data = load(filename,'originalData');

%
% Plot the data.

plot(data.originalData);

% Copyright 2012 The MathWorks, Inc.