如何使用 surf 或 mesh 显示二维矩阵?

How to display a 2-D matrix using surf or mesh?

假设我有一个矩阵 A,我如何用 surfmesh 显示它,X-Y 轴是元素的索引(例如 i,j) Z 值是 A(i,j)?

中的值

您可以直接将它传递给surf,它会自动使用索引作为 x 和 y 坐标

data = rand(10)
surf(data);

surf(Z) creates a three-dimensional shaded surface from the z components in matrix Z, using x = 1:n and y = 1:m, where [m,n] = size(Z). The height, Z, is a single-valued function defined over a geometrically rectangular grid. Z specifies the color data, as well as surface height, so color is proportional to surface height. The values in Z can be numeric or datetime or duration values.