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

前端 未结 3 521
北恋
北恋 2020-12-09 22:49

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 follo

相关标签:
3条回答
  • 2020-12-09 23:04

    Maybe this user-created plotting routine can help.

    Screnshot from the linked page: Screnshot from the linked page

    0 讨论(0)
  • 2020-12-09 23:04

    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.

    0 讨论(0)
  • 2020-12-09 23:08

    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

    0 讨论(0)
提交回复
热议问题