Reputation: 107
I have a matrix of drill hole positions ([X Y]). I have extracted the unique positions ([Xuq Yuq]) and then interpolated an elevation (Z) for each using griddata. Now I want to create a column in the original matrix with the relevant Z assigned back to every X & Y position. Is this possible without for loops?
Upvotes: 0
Views: 63
Reputation: 4469
If you created your unique positions and the elevation by doing something like:
XY = unique(data(:,[1 2]),'rows');
Z = f(XY); % some function of XY(:,1) and XY(:,2)
Then all you need to do is keep the third output value from unique and use that to map Z
back in appropriately:
[XY,~,ic] = unique(data(:,[1 2]),'rows');
Z = f(XY);
data = [data Z(ic)]; % append the mapped column
Upvotes: 1