variable transparency in surface plot

13 visualizaciones (últimos 30 días)
felix
felix el 21 de Abr. de 2014
Comentada: felix el 22 de Abr. de 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 comentarios
Jan
Jan el 21 de Abr. de 2014
What does "Matlab crash" exactly mean?
felix
felix el 22 de Abr. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 21 de Abr. de 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 comentario
felix
felix el 22 de Abr. de 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!

Iniciar sesión para comentar.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by