Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB: Need to make a 4D plot (3D + Colour/Color)

I need to make a 3D surface where colour will represent the fourth variable. I know "surf" is SIMILAR to what I need, but that's not quite it. Basically, I have the following variables:

t = [1:m]

y = [1:n]

a = [1:o]

These should be the three Cartesian corodinate axes.

I also have a variable S that is of dimensions m x n x o, and is basically the amplitude, a function of the previous three variables (i.e. S = f(t,y,a)). I want this to be represented by colour.

So to summarize, I need a graph of the form (t,y,a,S), where the first three variables are vectors of unequal sizes and the final variable is a multidimensional array whose dimensions are determined by the first three.

Thanks in advance.

like image 206
Mike Avatar asked Mar 31 '12 23:03

Mike


People also ask

How do I change the plot color in Matlab?

You can change the colors, line styles, and markers of plot objects by modifying the ColorOrder or LineStyleOrder properties of the axes, or by changing the SeriesIndex properties of the plot objects.

Why is my 3d plot black Matlab?

The issue occurs when the grid which your surface is plotted over contains a large number of points. The lines which create the wire mesh surface are black by default and take precedence over the color map. In this situation, the wire grid is so dense that the lines form a completely black surface.

How do you plot a 3d plot in Matlab?

plot3( X , Y , Z ) plots coordinates in 3-D space. To plot a set of coordinates connected by line segments, specify X , Y , and Z as vectors of the same length. To plot multiple sets of coordinates on the same set of axes, specify at least one of X , Y , or Z as a matrix and the others as vectors.


2 Answers

SCATTER3 requires x, y and z and other grouping arguments to be equally-sized Nx1 vectors for a single series or NxM matrices for M series.

You have full space 3D data. To make equally-sized coordinate vectors use MESHGRID (or NDGRID) function:

[X, Y, Z] = meshgrid(t, y, a);

Then you can use SCATTER3:

scatter3( X(:), Y(:), Z(:), [], S(:) )

The problem is since it's full space data scatter3 will not be helpful specially if you have a lot of points.

You can probably filter your S variable (something like idx = S > 0), then you can plot filtered data.

If you really need to visualize all the data, look at Volume visualization in MATLAB documentation. I can recommend SLICE function, for example.

EDIT

Here is an example of full 3D space scatter plot for small vectors (m, n, o equal to 5) with S = rand([m,n,o]); scatter3( X(:), Y(:), Z(:), [], S(:), 'filled' )

scatter example

EDIT 2

From your comments to the other answer I found that you have 32x76050x4 matrix. You can actually plot 2D slice one at a time. you can do it in 2D with IMAGESC function, or in 3D with SLICE function.

Try:

imagesc(S(:,:,k))

where k is a number from 1 to 4 for the 3rd dimension.

Or try

slice(S, [], [], 1:size(S,3))
shading flat

slice example

like image 160
yuk Avatar answered Nov 11 '22 07:11

yuk


Maybe this user-created plotting routine can help.

Screnshot from the linked page: Screnshot from the linked page

like image 38
AllanLRH Avatar answered Nov 11 '22 09:11

AllanLRH