0
votes

I would like to plot a uniform height grid in Matlab, i have a way to do this but it is just too slow. Currently i have height grid data which i convert into x, y, z points. I then run the following code:

    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

In case you desperatley need to know, get colour does this:

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

Now this works and produces essentially what i want:

enter image description here

Unfortunately, it is so slow. And really what can i expect, i am looping over a height grid and plotting shapes to the screen 1 by 1. Unfortunately, i cannot think of anything that will produce the same result and be fast in Matlab. I am hoping a matlab guru might have a better idea.

1

1 Answers

0
votes

I figured it out. Using patch is a lot faster:

    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;