function callback(n, var1, var2, param, val, f)
%CALLBACK plot var1 and var2 shifted or scaled according to param with the
%   value val on the figure f;
%
% Inputs: 
%    Required:
%        n Nx1 double containing the x variable to plot
%        var1 Nx2 double containing the first y variable to plot
%        var2 Nx2 double containing the second y variable to plot
%        param string specifying which modification will be done
%           shit or scale
%        val double containing the new value for to use for param
%        f figure handler of the figure to update
%    Global:
%        shift_ double 
%        scale_ double
%
% Outputs:
%    update figure f
%    Global:
%        shift_ double updated with value if param == 'shift'
%        scale_ double updated with value if param == 'scale'
%
% Example:
% set(b,'Callback', @(es,ed) callback(n, var1, var2, 'scale', -es.Value, fp));
%
% Tested with: Matlab R2015a
%
% Author: Nils Haentjens, Ms, University of Maine
% Email: nils.haentjens@maine.edu
% Created: 21th July 2015
% Last update: 22th July 2015

% Check input
if nargin > 5
   error('Too many input arguments')
elseif nargin < 5
   error('Not enough input arguments')
end

% Set global var
global shift_ scale_;
if strcmp(param, 'shift');
  shift_ = val;
elseif strcmp(param, 'scale');
  scale_ = val;
end;

% Update plot
set(0,'CurrentFigure',f);
plot(n, var1, n-shift_, scale_*var2);
title(sprintf('shift of: %d steps', shift_));
end