% Jake Bobowski
% June 8, 2016
% Created using MATLAB R2014a

% This MATLAB script is designed to show you how to export data to a file.
% First a very simple example.  We generate a x vector with elements 1 to
% 10 in steps of 2.  We also calculate y2 and y3 values as x^2 and x^3,
% respectively.

x = [1:2:10];
y2 = x.^2;
y3 = x.^3;

% Ultimately, I intend to export a matrix of data to my file.  The matrix
% is constructed as follows:
[x; y2; y3]

% The matrix above has x as the first row, y2 as the second row, and y3 as
% the third row.  I'd rather have x as the first column, y2 as the second
% column, and y3 as the third column.  This is achieved by transposing the
% matrix above using '.
M = [x; y2; y3]'

% We use dlmwrite to export the data to a file.  This line will write the
% data to a file in the same directory as the MATLAB script (.m file).  The
% default is to use comma-deliminted data.  I prefer tab-delimited data so
% I will specific that as an option.
dlmwrite('matrix data.txt',M,'delimiter','\t')

% You can, of course, specify a different folder.  The line below will
% write the file to a folder called 'data folder' which is contained within
% the same folder as the MATLAB script.
dlmwrite('data folder\matrix data.txt',M,'delimiter','\t')

% You can also specify a path that is independent of the loaction of the
% MATLAB script.
dlmwrite('G:\UBCO\matrix data.txt',M,'delimiter','\t')