function ht = PlotModeChanges(modeTime, mode, varargin) % PlotModeChanges Plot vertical lines when control mode changes using flight % data from ArduCopter % % Inputs: % modeTime : [vector] (sec) time when mode change occurs % mode : [vector] numerical value indicating mode % axh : [scalar] axis handle for plotting - if empty use current figure % varargin(2:end) : Name-value pair arguments to format the vertical lines % indicating mode change % % Outputs: % ht : handle to graphics indicating mode change % plotOpt = []; if isempty(varargin) axh = gca; elseif nargin > 3 plotOpt = varargin(2:end); axh = varargin{1}; end if ~ishold(axh) hold(axh,'on') end ylim = get(axh, 'Ylim'); % Get the map of control mode for ArduCopter fmodeNum = ArduCopterMode; numMode = length(mode); for kk = 1:numMode ht = plot(axh, modeTime(kk)*ones(1,2), ylim, plotOpt{:}); ht.Color = [fmodeNum(mode(kk)).Col, 0.5]; ht.Tag = fmodeNum(mode(kk)).Val; end % set the data cursor to display the mode type figh = GetFigureHandle(axh); CustomDataCursor(figh); function figh = GetFigureHandle(ob) temp = ob.Parent; if ~isa(temp, 'matlab.ui.Figure') temp = GetFigureHandle(temp); end figh = temp; end end