function p_selected = hope_m_lessthan_n(p,m,n)

% pselect.m                                                    Steve Mann
%
% example: p_selected = pselect(p,9,11);
%          composes the 10th and 11th elements of p so that, 
%          if p is estimated pairwise, then p_selected maps image 11 to image 9
%
%          shouldbe5=pchirp2(pselect(p,5,11),v11);
%          makes v11 look much more like v05
%
% identity pselect(p,9,9) or backwards: shouldbe11=pchirp2(pselect(p,11,5),v05);

if nargin < 3
  error('pselect: need 3 input args: p, m, n')
end%if

[M,N]=size(p);
if N~=8
  error('pselect: parameters must be rows of 8 elements each row')
end%if

[M,N]=size(m);
if (M~=1) | (N~=1)
  error('pselect: m must be a scalar')
end%if

[M,N]=size(n);
if (M~=1) | (N~=1)
  error('pselect: n must be a scalar')
end%if

if m<n
  temp = pintegrate(p(m+1:n,:));
  [M,N]=size(temp);
  p_selected=temp(M,:); % last element
else%if
  if m==n
    disp('pselect: same frame asked for, so returning identity element')
    p_selected=[1 0 0 0 1 0 0 0];
  else%if
    disp('pselect: going backwards in order, so taking inverse')
    temp = pintegrate(p(n+1:m,:));
    [M,N]=size(temp);
    p_selected_inv = temp(M,:); % last element
    p_selected = pinverse(p_selected_inv); 
  end%if
end%if

