function [p,p0,ix1,ix2] = mergeParameters(p1,p2,p10,p20)
% Merge parameter names and test values.
% 
% P is the union of P1 and P2 with P1 = P(IX1) and P2 = P(IX2).

%  Copyright 2022 The MathWorks, Inc.
np1 = numel(p1);
np2 = numel(p2);
[p,iu,ix] = unique([p1;p2],'stable');  % [p1;p2] = p(ix)
ix1 = ix(1:np1);
ix2 = ix(np1+1:np1+np2);
p0 = [p10;p20];
p0 = p0(iu,:);
% Check consistency of test values for shred parameters
if numel(p)<np1+np2
   ix = intersect(ix1,ix2);  % p(ix) = parameters in common
   p10x = p10(ix);
   p20x = p20(ix);
   if ~any(p10x)
      p0(ix) = p20x;
   elseif ~any(p20x)
      p0(ix) = p10x;
   elseif ~isequal(p10x,p20x)
      error(message('Control:combination:LPV1'))
   end
end