Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

avoid duplicate points in griddata

1,424 views
Skip to first unread message

dfgdfg sdfg

unread,
Feb 24, 2009, 8:31:02 AM2/24/09
to
When we have duplicate points and use griddata we get the message
Warning: Duplicate x-y data points detected: using average of the z values.

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?

Damian Sheehy

unread,
Feb 24, 2009, 9:10:09 AM2/24/09
to
You do not have to change the griddata code to get the behavior that you
want.
Instead write a preprocessing function that will eliminate the duplicates
from your data, and in that function select the z value that you desire.
Then feed the unique dataset to griddata.

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...

0 new messages