How do I insert an image in my 2-D and 3-D plots in MATLAB 8.2 (R2013b)?

27 ビュー (過去 30 日間)
I want to display an image inside a 2-D plot and a 3-D plot. How can I do it?
 

採用された回答

MathWorks Support Team
MathWorks Support Team 2018 年 3 月 29 日
For 2-D plots:
You can use the function IMAGE. 
The following example plots an image at the center of a scatter plot:
 
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
 
 
For 3-D plots:
The IMAGE function is no longer appropriate. 
In this case you will have to create a 3-D surface using the SURF function and texture map the image onto it. 
The following example shows how to put an image in the middle of a 3-D scatter plot:
 
[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');

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLighting, Transparency, and Shading についてさらに検索

製品


リリース

R2013b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by