对于2-D图
功能IMAGE是您正在寻找的。以下是一个例子:
img = imread('peppers.png'); %# Load a sample image
scatter(rand(1,20)-0.5,rand(1,20)-0.5); %# Plot some random data
hold on; %# Add to the plot
image([-0.1 0.1],[0.1 -0.1],img); %# Plot the image
3-D图…
IMAGE功能不再合适,因为除非从正上方观察轴(即沿着正z轴),否则不会显示图像。在这种情况下,您必须使用SURF功能在3-D中创建一个曲面,并将图像映射到其上。以下是一个例子:
[xSphere,ySphere,zSphere] = sphere(16); %# Points on a sphere
scatter3(xSphere(:),ySphere(:),zSphere(:),'.'); %# Plot the points
axis equal; %# Make the axes scales match
hold on; %# Add to the plot
xlabel('x');
ylabel('y');
zlabel('z');
img = imread('peppers.png'); %# Load a sample image
xImage = [-0.5 0.5; -0.5 0.5]; %# The x data for the image corners
yImage = [0 0; 0 0]; %# The y data for the image corners
zImage = [0.5 0.5; -0.5 -0.5]; %# The z data for the image corners
surf(xImage,yImage,zImage,... %# Plot the surface
'CData',img,...
'FaceColor','texturemap');
请注意,该表面固定在空间中,因此在旋转轴时,图像不会始终直接面向相机。如果您希望纹理映射表面自动旋转,以便它始终垂直于摄像机的视线,这是一个更加涉及的过程。