matlab - 来自 X、Y、Z、V 的等值面在 Matlab/Octave 中有序数据

标签 matlab octave geometry-surface

我有一组 3d 数据点,每个数据点都与某个数量的值 V 相关联。数据按 X Y Z V 有序列组织,其中空间坐标分布在网格上。我每个方向都有21个点,这样几列的长度就是21x21x21=9261。如何将数据转换为可由 Octave/Matlab 中的 isosurface 使用的网格?我的代码如下

a=load("data.txt");
X=reshape(a(:,1), 21,21,21);
Y=reshape(a(:,2), 21,21,21);
Z=reshape(a(:,3), 21,21,21);
V=reshape(a(:,2), 21,21,21);
fv=isosurface (X,Y,Z,V,0.9);
patch(fv)

但结果没有意义(我得到两个位于 x=0.9 和 1 处的平面)。资料可下载here .

最佳答案

这是为您的数据创建适当网格的一种方法:

a = load('data.txt');
[X, Y, Z] = meshgrid(unique(a(:, 1)), unique(a(:, 2)), unique(a(:, 3)));
V = zeros(21, 21, 21);
for i = 1:numel(V)
  idx = find(a(:, 1) == X(i) & a(:, 2) == Y(i) & a(:, 3) == Z(i));
  V(i) = a(idx, 4);
end
fv = isosurface (X,Y,Z,V,0.9);
p = patch(fv);
set(p,'FaceColor','red','EdgeColor','none');
camlight;
lighting gouraud;
xlabel('x');
ylabel('y');
zlabel('z');

enter image description here

如果您有更大的数据并且这太慢了,我可能会想出一种 reshape 原始数据的方法来避免我在上面使用的 for 循环。

关于matlab - 来自 X、Y、Z、V 的等值面在 Matlab/Octave 中有序数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14220713/

相关文章:

python - MATLAB 引擎和 Imatest IT 的导入冲突

math - Octave:哪种方法更有效

r - 在 R 曲面图中插入 "cut off"字段

algorithm - 在 THREEJS 网格中对共面三角形进行分组的方法?

点云的Matlab Delaunay三角剖分-颜色矩阵

algorithm - 反转符号不起作用

matlab - 多维矩阵乘法

image - 估计图像线梯度(不是像素梯度)

macos - 在Mac上从 Octave 播放音频的可能方法是什么?

ubuntu - 在 Ubuntu 上编译 Octave 脚本时出现解析错误