我不认为你可以用Matlab的内置命令和功能做你想做的事.但是使用
my other answer中的技术和高分辨率版本的网格可以为您完成.
“高分辨率”是指具有更密集数据点的非均匀网格的插值版本.这用于在更密集的数据点处对纹理进行采样,因此可以使用surf的texturemap特征进行绘制.但是,您不能使用普通的2D插值,因为您需要保留不均匀的网格形状.这就是我提出的:
function g = nonUniformGridInterp2(g, sx, sy)
[a,b] = size(g);
g = interp1(linspace(0,1,a), g, linspace(0,1,sy)); % interp columns
g = interp1(linspace(0,1,b), g', linspace(0,1,sx))'; % interp rows
请注意,您必须调用此方法两次才能独立插入X和Y点.这是原始网格和每个方向上有10个点的插值版本的示例.
以下是如何使用具有interp2和texturemap的高分辨率网格.
function nonUniformTextureMap
% define the non-uniform surface grid
X = [310,270,330; 430,410,400; 480,500,520];
Y = [300,400,500; 300,400,500; 300,400,500];
Z = [300,330,340; 300,310,330; 290,300,300];
% get texture data
load penny % loads data in variable P
% define texture grid based on image size
% note: using 250-550 so that a,b covers the range used by X,Y
[m,n] = size(P);
[a,b] = meshgrid(linspace(250,550,n), linspace(250,550,m));
% get a high-res version of the non-uniform grid
s = 200; % number of samples in each direction
X2 = nonUniformGridInterp2(X, s, s);
Y2 = nonUniformGridInterp2(Y, s, s);
% sample (map) the texture on the non-uniform grid
C = interp2(a, b, P, X2, Y2);
% plot the original and high-res grid
figure
plot(X(:),Y(:),'o',X2(:),Y2(:),'.')
legend('original','high-res')
% plot the surface using sampled points for color
figure
surf(X, Y, Z, C, 'edgecolor', 'none', 'FaceColor','texturemap')
colormap gray