I'm not sure how you can have a 300x300x300 matrix for a point cloud in 3-D. I will assume you have a 300x300x3 matrix, i.e.:
x = matrix(:,:,1);
y = matrix(:,:,2);
z = matrix(:,:,3);
First of all, you probably want to rearrange points into a 2D matrix:
m = reshape(matrix, numel(matrix(:,:,1), 3);
n = size(m,1);
Your matrix is now arranged as a n-by-3 matrix, coloumn 1, 2 and 3 representing x-, y- and z-axis respectively, i.e.:
m = [ x1 y1 z1]
[ x2 y2 z2]
[ ... ]
[ xn yn zn]
Then you can create a basic 3D scatter plot:
scatter3(m(:,1), m(:,2), m(:,3))
However, this is not what you want, because points are in the same colour. To add colour based on your colouring logic, you should firstly create a color matrix using one of the MATLAB's built-in color maps. Here I use jet
:
myc = jet(n);
You can also create your own colour map ofc. Elements in the colour matrix are simply normalised rgb values.
Now you will have to weight each points using your own logic:
weighting = myWeightingLogic(m);
weighting
will be a n-by-1 vector and it should be normalised if it is not yet.
weighting = weighting/max(weighting);
Now you can colour your scatter plot:
scatter3(m(:,1), m(:,2), m(:,3)), [], myc(round(weighting*n),:));
The full code:
m = reshape(matrix, numel(matrix(:,:,1), 3);
n = size(m,1);
myc = jet(n);
weighting = myWeightingLogic(m);
weighting = weighting/max(weighting);
scatter3(m(:,1), m(:,2), m(:,3)), [], myc(round(weighting*n),:));