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 个评论
Adam Danz
2021-4-25
"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.
回答(1 个)
Walter Roberson
2021-4-26
V(V==0)=NaN
h=slice(V,50,50,50)
set(h, 'Alphadata', double(~isnan(V)));
2 个评论
Adam Danz
2021-4-26
Hmmmm but the alphadata property of surface objects accepts logical arrays according to the documentation.
Walter Roberson
2021-4-26
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!