Home > OS >  Plotting a coloured 3D figure in MATLAB
Plotting a coloured 3D figure in MATLAB

Time:09-20

I have 3 axes: X of size N, Y of size M and Z of size O, which correspond to the coordinates of my data.

I have a matrix: DATA of size MxNxO, which corresponds to the module for each points.

I would like to plot the MATLAB figure of coordinate X, Y, Z and color the point depending of the value of the matrix DATA of size MxNxO.

I tried lots of functions such as scatter3, surf, plot3, but none is working as I wanted.

This is what I tried:

n = 10;
x = linspace(0,10,n);
y = linspace(0,10,n);
z = linspace(0,10,n);

DATA = randn(n,n,n);

scatter3(x,y,z,DATA);

This code didn't work because DATA is not the same size as x, y, z. I also tried with:

[X,Y,Z] = ndgrid(x,y,z) 
scatter3(X,Y,Z,DATA);

but this didn't work either.

CodePudding user response:

The trick with enter image description here

You can colour a surface, see its enter image description here

Images rendered in R2007b, syntax cross-checked with the documentation.

If you've got a surface defined by an M -by- 4 array containing X, Y, Z and Data, you can use delaunay() to create a Delaunay triangulation of your points and then trisurf() to plot that. Note that this still requires a 2D surface, albeit it can vary in three dimensions. The cube of data in your example still doesn't make sense to plot as a surface, even with this method.

  • Related