7

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.

Tim Penner
  • 3,551
  • 21
  • 36
Mike
  • 71
  • 1
  • 1
  • 3

3 Answers3

10

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

yuk
  • 19,098
  • 13
  • 68
  • 99
  • Thank you, I will try this! I will update you when I get the results! =D – Mike Apr 01 '12 at 06:40
  • Can you post a screenshot of what that looks like, if possible? I'm curious. Thanks! – rutgersmike Apr 03 '12 at 14:38
  • Screenshot of what? scatter plot? Remember it's full space, so it will not make much sense unless you filter the data. I can show it for small vectors. – yuk Apr 03 '12 at 15:08
  • I've always been a big fan of [ISOSURFACE](http://www.mathworks.com/help/techdoc/ref/isosurface.html) for 4-D visualization. A few transparent isosurfaces can make a very pretty plot. ;) – gnovice Apr 03 '12 at 15:25
  • @gnovice: Yea, it could be cool. I didn't know. The problem in this case is only 4 levels in 3rd dimension. – yuk Apr 03 '12 at 15:32
3

Maybe this user-created plotting routine can help.

Screnshot from the linked page: Screnshot from the linked page

Community
  • 1
  • 1
AllanLRH
  • 1,124
  • 1
  • 12
  • 23
1

I've always used scatter3 for coloring/sizing pixels in 3d space. I believe the signature is:

scatter3(x,y,z, size, color)

The size and color can be scalar or vector of length equal to the coordinates. I usually use either the color or the size to reflect the fourth attribute, depending on what I'm showing. I don't have Matlab on this machine, so forgive me if my memory isn't completely accurate on the usage. "help scatter3" should describe it much better.

rutgersmike
  • 1,183
  • 9
  • 18
  • Thanks, I was also suggested this on the MATLAB forums. I'll look into it. However, in my case, what would I do with the size variable? That one I'm not concerned about, but I am interested in the other four. – Mike Apr 01 '12 at 00:11
  • I have a set of time-domain signals that are separated in space, and I have taken the continuous-wavelet transform of them to get a scalogram. Thus, I have three variables as the axes: time (t), space (x), and scales/frequency (a), as well as the actual scalogram itself--or rather, a set of scalograms for each of the different spatially separated signals. time is of length 76050 scales is of length 32 space is of length 4 Thus, the set of scalograms is a multidimensional array of length 32x76050x4, with the actual values inside representing the amplitude. It's pretty confusing. – Mike Apr 01 '12 at 00:15
  • I just thought of an idea. What if I scaled the variables appropriately so that their sizes can fit into a function like surf or scatter3D? So currently, the variables are like 32x76050x4. Using linspace or something along those lines, I should be able to make thse guys line up. Let me give this a try. – Mike Apr 01 '12 at 02:52