% I have three vectors of values vi on different zones (xi,yi) with overlapping areas i.e. they share some
% exact positions
% I build the global domain
Xd = [x1 x2 x3];
Yd = [y1 y2 y3];
% I remove the duplicates
[~,inds,~] = unique([Xd,Yd],'rows','stable');
Xd = Xd(inds);
Yd = Yd(inds);
% I put each zone on the global domain
% this means that I need to find where (xi,yi) are locatedd in (Xd,Yd)
% hence the ismember over all couples
v1g = nan(size(Xd));
Iin = ismember([Xd,Yd],[x1,y1],'rows')
v1g(Iin) = v1;
v2g = nan(size(Xd));
Iin = ismember([Xd,Yd],[x2,y2],'rows')
v2g(Iin) = v2;
v3g = nan(size(Xd));
Iin = ismember([Xd,Yd],[x3,y3],'rows')
v3g(Iin) = v3;
% I get the mean
meand = mean([v1g v2g v3g],2,'omitnan');
