%% Write Matrix to Text File
% Create a matrix, write it to a comma-separated text file, and then write the matrix to another text file with a different delimiter character.
% Create a matrix in the workspace.

M = magic(5)

% Write the matrix to a comma delimited text file and display the file contents. The writematrix function outputs a text file named M.txt.

writematrix(M)
type 'M.txt'

% To write the same matrix to a text file with a different delimiter character, use the 'Delimiter' name-value pair.

writematrix(M,'M_tab.txt','Delimiter','tab')
type 'M_tab.txt'

% Copyright 2018 The MathWorks, Inc.