My problem is that i don't want to use the average of the z values,but the last value of z that is found.Inside griddata we can see the code
% Sort x and y so duplicate points can be averaged before passing to delaunay
% Need x,y and z to be column vectors
sz = prod(size(x));
x = reshape(x,sz,1);
y = reshape(y,sz,1);
z = reshape(z,sz,1);
sxyz = sortrows([x y z],[2 1]);
x = sxyz(:,1);
y = sxyz(:,2);
z = sxyz(:,3);
myeps = max(max(abs(x)),max(abs(y)))*eps^(1/3);
ind = [0; ((abs(diff(y)) < myeps) & (abs(diff(x)) < myeps)); 0];
if sum(ind) > 0
warning('MATLAB:griddata:DuplicateDataPoints',['Duplicate x-y data points ' ...
'detected: using average of the z values.']);
fs = find(ind(1:end-1) == 0 & ind(2:end) == 1);
fe = find(ind(1:end-1) == 1 & ind(2:end) == 0);
for i = 1 : length(fs)
% averaging z values
z(fe(i)) = mean(z(fs(i):fe(i)));
end
x = x(~ind(2:end));
y = y(~ind(2:end));
z = z(~ind(2:end));
end
I guess i have to change something in that code to get what i want,but i don't know what to do to keep the last values of z that griddata finds.
Any suggestions?
Take a look at the UNIQUE function, it will find and classify your
duplicates.
Try this example to see how it behaves ( 2, 3 and 4, 5 are duplicate
locations)
x = [1 2; 2 3; 3 4; 4 5; 2 3; 4 6; 4 5]
[B, I, J] = unique(x,'last','rows');
B
I
J
The I vector can be used to index into the z values that you need - it
contains an index of the unique z's and the last occurrence of each
duplicate.
So when you call griddata pass the B matrix together with the associated
values z(I).
I hope that resolves your problem.
Damian
"dfgdfg sdfg" <zfd...@fg.gh> wrote in message
news:go0sql$mh4$1...@fred.mathworks.com...