MATLAB:需要制作 4D 绘图(3D + 颜色/颜色) [英] MATLAB: Need to make a 4D plot (3D + Colour/Color)
问题描述
我需要制作一个 3D 表面,其中颜色将代表第四个变量.我知道冲浪"与我需要的很相似,但并非如此.基本上,我有以下变量:
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.
我还有一个变量 S,其维度为 m x n x o,基本上是振幅,是前三个变量的函数(即 S = f(t,y,a)).我希望这用颜色表示.
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.
总而言之,我需要一个 (t,y,a,S) 形式的图,其中前三个变量是大小不等的向量,最后一个变量是一个多维数组,其维度由前三个决定.
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.
提前致谢.
推荐答案
SCATTER3 需要 x
、y
和 z
和其他分组参数来对于单个系列是大小相同的 Nx1 向量,对于 M 系列是 NxM 矩阵.
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.
您拥有全空间 3D 数据.要制作大小相等的坐标向量,请使用 MESHGRID(或 NDGRID) 函数:
You have full space 3D data. To make equally-sized coordinate vectors use MESHGRID (or NDGRID) function:
[X, Y, Z] = meshgrid(t, y, a);
然后就可以使用SCATTER3了:
Then you can use SCATTER3:
scatter3( X(:), Y(:), Z(:), [], S(:) )
问题是因为它是全空间数据,如果你有很多点,scatter3 不会特别有用.
The problem is since it's full space data scatter3 will not be helpful specially if you have a lot of points.
您可能可以过滤您的 S 变量(类似于 idx = S > 0
),然后您可以绘制过滤后的数据.
You can probably filter your S variable (something like idx = S > 0
), then you can plot filtered data.
如果您真的需要可视化所有数据,请查看Volume可视化 在 MATLAB 文档中.例如,我可以推荐 SLICE 函数.
If you really need to visualize all the data, look at Volume visualization in MATLAB documentation. I can recommend SLICE function, for example.
编辑
以下是小向量(m
、n
、o
等于 5)的全 3D 空间散点图示例,S = rand([m,n,o]);scatter3( X(:), Y(:), Z(:), [], S(:), '填充')
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' )
编辑 2
从你的评论到另一个答案,我发现你有 32x76050x4 矩阵.您实际上可以一次绘制一个 2D 切片.您可以使用 IMAGESC 功能在 2D 中进行,也可以使用 SLICE 功能在 3D 中进行.
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.
试试:
imagesc(S(:,:,k))
其中 k
是从 1 到 4 的第三维数.
where k
is a number from 1 to 4 for the 3rd dimension.
或者试试
slice(S, [], [], 1:size(S,3))
shading flat
这篇关于MATLAB:需要制作 4D 绘图(3D + 颜色/颜色)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!