function vv = FindMPs(xwhat,ywhere,FirstLast);
%FindMPs    Find indices (vv) of several values (xwhat) in a vector ywhere,
%           such that ywhere(vv) == xwhat (provided no NaN). Only the first/last
%           occurence is recorded.
%
%
%
%
%  Usage:    vv = FindMPs(xwhat,ywhere,FirstLast); or
%               = FindMPs(xwhat,ywhere);
%
%  Input:    xwhat      Nx1 vector, to find
%            ywhere     Mx1 vector, where to find it
%            FirstLast  string, 'first' or 'last'  (default: 'first')
%
%  Output:  vv          Nx1 vector, indices
%
%
%
%
%
%  Paul.Soderlind@unisg.ch, 2000
%----------------------------------------------------------------------------

if nargin < 3;
  FirstLast = 'first';
end;

N     = length(xwhat);

vv    = NaN(N,1);
for i = 1:N;
  vv_i = find( xwhat(i) == ywhere,1,FirstLast );
  if ~isempty(vv_i);
    vv(i) = vv_i(1);
  end;
end;
%----------------------------------------------------------------------------

