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

%Clear all variable assignments.
clearvars

%Display numbers using scientific notation.
format shortE;

% Import data.  Use 'dlmread' to import the data contained in the file
% 'short - 085 - 10 MHz - 13.5 GHz - 00.txt'.  In this example, the file
% must be contained in the same folder as the MATLAB script (*.m file).
% The size() function tells us that MATLAB has imported the data as a
% matrix with 3201 rows and 3 columns.
Short = dlmread('short - 085 - 10 MHz - 13.5 GHz - 00.txt');
size(Short)

% Import data.  Use 'dlmread' to import the data contained in the file
% 'short - 085 - 10 MHz - 13.5 GHz - 00.txt'.  In this example, the file
% is in a folder called 'data folder' that is contained in the same folder
% as the MATLAB script (*.m file).  This line will only work for you if you
% create 'data folder' and put the data file in it.
Short = dlmread('data folder\short - 085 - 10 MHz - 13.5 GHz - 00.txt');
size(Short);

% Import data.  Use 'dlmread' to import the data contained in the file
% 'short - 085 - 10 MHz - 13.5 GHz - 00.txt'.  In this example, the entire
% path leading to the file is specified.  This line will not work for you
% because you won't have the same folder structure that I have.  You'll
% have to make the appropriate edits.
Short = dlmread('G:\UBCO\2016-2017\MATLAB\short - 085 - 10 MHz - 13.5 GHz - 00.txt');
size(Short);

% To isolate the first column, use Short(:,1)
freq = Short(:,1);
size(freq)
length(freq)

% Typically you want a row vector rather than a column vector.  You can use
% ' to transpose the vector as follows:
freq = Short(:,1)';
size(freq)
length(freq)
% Notice that the matrix went from being 3201 x 1 to 1 x 3201.

% Here are the second and third columns converted to row vectors.
realPart = Short(:,2)';
imagPart = Short(:,3)';

% We can now manipulate and plot the data as usual.  For example, here's
% the manitude of the complex data set ploted on a log-log scale.
mag = sqrt(realPart.^2 + imagPart.^2);
loglog(freq,mag)
xlabel('Frequency (Hz)');
ylabel('Reflection Coefficient Magnitude');
ans =

        3201           3


ans =

        3201           1


ans =

        3201


ans =

           1        3201


ans =

        3201