% get_kxv( el, k) - get x,y and velocity values from Kalman kxv array
% where el selects el'th best 1..L and k selects track 1..K.
% Default values are el=1, k=1
%
function r = get_kxv( el, k)

global K;
global L;
global N;
global M;
global path_index;
global el_index;
global kxv;

if( nargin == 0)
  el = 1;
  k = 1;
end

if( nargin == 1)
  k = 1;
end

if( (el < 1) | (el > L))
  error( '1 <= el <= L required');
end

if( (k < 1) | (k > K))
  error( '1 <= k <= K required');
end

r = zeros(4,N);

for i = 1:N
  if( path_index(el,i) > 0)
    j = [1:4] + (el_index(el,i)-1)*4;
    i1 = k + ((i-1)*M + (path_index(el,i)-1))*K;
    r(:,i) = kxv(j,i1);
  end
end

r = r';
