variable transparency in surface plot

8 views (last 30 days)
felix
felix on 21 Apr 2014
Commented: felix on 22 Apr 2014
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 Comments
Jan
Jan on 21 Apr 2014
What does "Matlab crash" exactly mean?
felix
felix on 22 Apr 2014
"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.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 21 Apr 2014
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 Comment
felix
felix on 22 Apr 2014
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!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!