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