0

我想在 Matlab 中绘制一个统一的高度网格,我有办法做到这一点,但它太慢了。目前我有高度网格数据,我将其转换为 x、y、z 点。然后我运行以下代码:

    figure;
    hold on;
    axis equal;
    minHeight = min(z)
    maxHeight = max(z)
    gX = HG.xCellSize/2;
    gY = HG.yCellSize/2;
    for i = 1:length(x)

        colour = getColour(minHeight, maxHeight, z(i));

        p1X = [x(i)-gX, x(i)+gX, x(i)+gX, x(i)-gX];
        p1Y = [y(i)+gY, y(i)+gY, y(i)-gY, y(i)-gY];
        p1Z = [z(i), z(i), z(i), z(i)];
        p1C = [colour, colour, colour, colour];

        fill3(p1X, p1Y, p1Z, p1C)

    end

如果您需要知道,请获取颜色:

function [colour] = getColour(min, max, height)
    colour = floor((max-height)/(max-min)+1);
end

现在这有效并基本上产生了我想要的东西:

在此处输入图像描述

不幸的是,它太慢了。我真的可以期待什么,我在一个高度网格上循环并在屏幕上 1 个 1 绘制形状。不幸的是,我想不出任何可以在 Matlab 中产生相同结果并且速度很快的东西。我希望matlab大师可能有更好的主意。

4

1 回答 1

0

我想到了。使用补丁要快得多:

    axis equal;
    minHeight = min(z);
    maxHeight = max(z);
    gX = HG.xCellSize/2;
    gY = HG.yCellSize/2;
    patchX = [];
    patchY = [];
    patchZ = [];
    for i = 1:length(x)

         p1X = [x(i)-gX; x(i)+gX; x(i)+gX; x(i)-gX; ];
         patchX = [patchX, p1X];
         p1Y = [y(i)+gY; y(i)+gY; y(i)-gY; y(i)-gY];
         patchY = [patchY, p1Y];
         p1Z = [z(i); z(i); z(i); z(i)];
         patchZ = [patchZ, p1Z];

    end

    patch(patchX, patchY, patchZ, patchZ);
    colorbar;
于 2013-07-05T03:03:17.503 回答