简体   繁体   English

MATLAB:根据不规则数据点绘制3D曲面

[英]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: 假设我有一个x坐标向量,一个y坐标矩阵和相应的z值:

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? 如何在相应的x和y值给出的点上绘制由z值确定的曲面? 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. 第一个x值定义矩阵第一行中所有y值的x值,第二个x值定义第二行中的所有值,依此类推。

(If the answer is griddata I would like some additional pointers. How can I get my data into the correct format?) (如果答案是griddata我还需要一些其他指针。如何将数据转换为正确的格式?)

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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