Problem in "Slice" function about Alphadata

Hi, recently, I update my Matlab to 2021a, before this, the version is Matlab 2019b. When I use slice function in Matlab 2019b, for example, V is a 3D (100*100*100) array, its values are 1 or 0, I use
V(V==0)=NaN
h=slice(V,50,50,50)
set(h,'Alphadata',~isnan(V));
and it works, it means that the 'NaN' area become white, however, same code in Matlab2021a doesn't work, I cannot understand the reason.

댓글 수: 2

"it doesn't work" tells us nearly nothing. I assume you're getting an error message in which case you should always share the entire error message.
V = randi(2,100,100,100)-1;
V(V==0)=NaN
h=slice(V,50,50,50)
set(h,'Alphadata',~isnan(V)); % < -- generates error
error message
Error using matlab.graphics.primitive.Surface/set
Error setting property 'AlphaData' of class 'Surface':
Value must be a scalar, vector or array of numeric or logical type.
Adam Danz
Adam Danz 2021년 4월 25일
h contains surface objects. See the documentation for AlphaData and its relationship to AlphaDataMapping also described on the same page.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2021년 4월 26일

0 개 추천

V(V==0)=NaN
h=slice(V,50,50,50)
set(h, 'Alphadata', double(~isnan(V)));

댓글 수: 2

Adam Danz
Adam Danz 2021년 4월 26일
Hmmmm but the alphadata property of surface objects accepts logical arrays according to the documentation.
Your data is 3D. isnan() of it would be 3D. You cannot set AlphaData to a 3D array.
However, you do not have to. You are setting the values to NaN, and NaN is always see-through. But what you should do is set the EdgeColor to 'none' so that it does not draw the fine lines around each element.
V(V==0) = NaN;
h = slice(V,50,50,50, 'edgecolor', 'none')
Now if you want a particular color for NaN, then you can get part way there by making sure that there is an object of the relevant color "behind". The default for axes on electric display is white behind (but watch out for saving to printer, where it might automatically inverse to black according to the Axes properties.)
If you want to fill the holes with a paticular color, you would pretty much need to take the isnan() matrix and slice() it at the same locations, specifying the surface color as the color you want to fill in the holes.
Note that if you were able to use alphadata 0 for this purpose, then the result is exactly the same as using NaN in those locations. NaN in a location is an automatic AlphaData 0 equivalent at that location.

댓글을 달려면 로그인하십시오.

카테고리

태그

질문:

2021년 4월 25일

댓글:

2021년 4월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by