variable transparency in surface plot

13 次查看(过去 30 天)
felix
felix 2014-4-21
评论: felix 2014-4-22
I'm trying to represent as a colored planar surface in 3d and would like to use variable transparency across the entries using the surface command. If 'CData' is an array of size m x n x 3, does 'AlphaData' have to be three-dimensional as 'CData' or of size m x n?
The following code does not produce the intended result for 2-dimensional 'AlphaData' and makes matlab crash after executing the program if I use a 3d array for 'AlphaData':
CData = rand(4,4,3); % random color data
[X,Y] = meshgrid(0:0.25:1,0:0.25:1);
Z = zeros(size(X));
figure(1)
clf
h0 = surface(X,Y,Z,'CData',CData,'FaceColor','texturemap')
h1 = surface(X,Y,Z+1,'CData',CData,'FaceColor','texturemap')
view(10,60)
AlphaData = ones(4);
AlphaData(2:3,2:3)=.5;
set(h0,'Alphadata',AlphaData,'FaceAlpha','texturemap')
set(h1,'Alphadata',AlphaData,'FaceAlpha','texturemap')
Any helpful hints as to what goes wrong would be very much appreciated.
  2 个评论
Jan
Jan 2014-4-21
What does "Matlab crash" exactly mean?
felix
felix 2014-4-22
"Crashes" means that Matlab produces a figure but after any further action from my side (moving the mouse), a window opens stating that "Matlab has encountered an internal problem and needs to close" because of a segmentation violation.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2014-4-21
AlphaData must be two dimensional.
For FaceColor of 'texturemap', CData does not need to be the same size as the ZData: it will be "stretched" to fit the ZData.
For FaceAlpha of 'texturemap', AlphaData does not need to be the same sze as the ZData or the CData: it will be "stretched" to fit the ZData.
  1 个评论
felix
felix 2014-4-22
My statement of the problem was probably a bit too brief:
1. When running the code with two-dimensional AlphaData, matlab produces surfaces where the inner part (AlphaData(2:3,2:3)=0.5) is completely transparent instead of half-transparent. The same happens if I replace 0.5 by 0.99.
2. For AlphaData(2:3,2:3)=1 on the other hand, the change of transparency by the set commands should have no effects. In this case however, all surfaces become nearly transparent!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by