function arAxes = plotMagNPhase(arMagnitude,arPhase,arFreq)
% function plotMagNPhase(arMagnitude,arPhase,arFreq)
%   This function plots the inputs arMagnitude and arPhase in a bode plot
%   style at the input frequency arFreq.
%
%   SgurrControl 2018
%   Project: IMPACT
%   Title of Code: getMagPhase
%   Relevant additional documentation: N/A
%   Developer: Carlos Gonzalez
%   External Dependencies: NA

%   Disclaimer
%   CAUTION: It is strongly recommended that changes to this code
%   should be avoided without first consulting with SgurrControl
%   and acquiring permission. SgurrControl is not liable for any
%   damage caused as a result of unauthorised changes to this
%   document.

%% Set up the colours for the plots
arColours=[0    0.4470    0.7410
0.8500    0.3250    0.0980
0.9290    0.6940    0.1250
0.4940    0.1840    0.5560
0.4660 0.6740 0.1880
0.3010 0.7450 0.9330];
iNumColors = size(arColours,1);
iNumChild = 0;

%% Create the magintude part of the plot
subplot(211)
xAxis211 = gca;
% set(xAxis211,'Tag','magnitudeAxes');
title('Bode plot')
if ~isempty(get(gca,'Children'))
%     hold on
    iNumChild = numel(get(gca,'Children'));
end
semilogx(arFreq,arMagnitude,'color',arColours(rem(iNumChild,iNumColors)+1,:),'linewidth',1.5);
ylabel('Magnitude (dB)')
grid on;

%% Create the phase part of the plot
subplot(212)
xAxis212 = gca;
% set(xAxis212,'Tag','phaseAxes')
% if ~isempty(get(gca,'Children'))
%     hold on
% end
semilogx(arFreq,arPhase,'color',arColours(rem(iNumChild,iNumColors)+1,:),'linewidth',1.5);
xlabel('Frequency (rad/s)')
ylabel('Phase (deg)')
grid on;

%% Link the axes together
linkaxes([xAxis211,xAxis212],'x');

arAxes = [xAxis211,xAxis212];
