Reputation: 567
I have a 3D matrix with values between 0
and 1
.
The matrix goes from (1,1,1)
to (k,k,k)
. For example, M(3,2,5) = 0.25
.
I want to plot this matrix in a 3D graph as a cloud of points, where each point will be colored with a gradient from transparent (0
) to black or other color (1
).
I'm not sure if you can use alpha in matlab... if not, then 0
will be just white.
Upvotes: 1
Views: 644
Reputation: 1797
You can use scatter3
with values from your matrix specifying the color of the point, and a white to black gradient would give you the same effect as transparency if the background is white. If you have a matrix M
of size [k k k]
To get the x,y,z
for your points you can use ind2sub
as follows:
>>[x,y,z] = ind2sub([k k k],1:numel(M));
And you can use scatter3
with this x,y,z as:
>>colors = [M(1:end)]'*[1 1 1]; % Get colors from black to white
>>scatter3(x,y,z,36,colors);
Upvotes: 1