0

I have given a 300x300x300 Matrix.

The first subscript represents the x-value, the second the y-value and the third the z-value.

To access a value of a specific point in the matrix i use:

matrix(x-val, y-val, z-val)

I want to create a 3D scatter plot where the color of the dots in the plot changes based on the values of the points in the matrix. All values are >=0

As i am pretty new to Matlab i have no idea where to start.

Tony
  • 604
  • 2
  • 6
  • 17
  • 2
    Are you sure it is not three separate matrices or a 300x300x3 matrix? If your matrix is 300x300x300, it means you have 90000 points in 300-D – Anthony Jul 12 '18 at 11:40
  • yes, i have generated it using `zeros(300,300,300)` – Tony Jul 12 '18 at 11:47
  • 1
    is this what you want? Do you have **volumetric** data? I.e. for each x,y,z, there is a matrix(x,y,z) value? https://stackoverflow.com/questions/27659632/plotting-volumetric-data-in-matlab/27660039#27660039 – Ander Biguri Jul 12 '18 at 12:51

2 Answers2

0

MathWorks has a page that summarizes types of MATLAB plots. I've referenced it on multiple occasions. The function you are looking for is scatter3(X,Y,Z,S,C). Walk through the function's example, it should help you out.

Juancheeto
  • 556
  • 4
  • 16
0

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),:));
Anthony
  • 3,595
  • 2
  • 29
  • 38