简体   繁体   中英

MATLAB: Plot 3D surface from irregular data points

Let's say I have a vector of x coordinates, a matrix of y coordinates and corresponding z values:

xcoordinates = [1 2 3 4 5];
ycoordinates = repmat(xcoordinates,5,1)+rand(5,5);
    z = zeros(5,5);
for x=xcoordinates
    for y=1:5
        z(x,y) = sqrt(x^2+ycoordinates(x,y)^2);
    end
end

How do I plot a surface determined by the z values at the points given by the corresponding x and y values? The first x value defines the x value for all y values in the first row of the matrix, the second x value to all values in the second row and so on.

(If the answer is griddata I would like some additional pointers. How can I get my data into the correct format?)

mesh(repmat(xcoordinates,5,1), ycoordinates, z)

By the way, you could easily vectorize this computation:

x = repmat(1:5, 5, 1);
y = x + rand(5,5);
z = sqrt(x.^2+y.^2);
mesh(x', y, z)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM