将唯一值相关的列映射到另一个矩阵中的所有值

Mapping a column related by unique values to all values in another matrix

我有一个钻孔位置矩阵 ([X Y])。我已经提取了独特的位置 ([Xuq Yuq]),然后使用 griddata 为每个位置插入了一个高程 (Z)。现在我想在原始矩阵中创建一个列,并将相关的 Z 分配回每个 X & Y 位置。如果没有 for 循环,这可能吗?

如果您通过执行以下操作创建了独特的位置和海拔高度:

XY = unique(data(:,[1 2]),'rows');
Z = f(XY); % some function of XY(:,1) and XY(:,2)

然后您需要做的就是保持第三个输出值不唯一,并使用它适当地映射 Z 回来:

[XY,~,ic] = unique(data(:,[1 2]),'rows');
Z = f(XY);
data = [data Z(ic)]; % append the mapped column