Understanding how to use the function griddata

10 次查看(过去 30 天)
graph = xlsread('Path3.xlsx');
x=graph(:,1);
y=graph(:,2);
z=graph(:,3);
[X,Y]= meshgrid(x,y);
Z = griddata(x,y,z,X,Y);
A = mesh(X,Y,Z);
hold on
surf(A);
hold off
xlabel('x'),ylabel('y'),zlabel('z'),title('title')
I have an excel file which I have imported with latitude, longitude and elevation in 3 columns. I'm trying to use the function meshgrid with the latitude and longitude values, and then the function griddata to fit the elevation data points to the meshgrid to develop a surface plot for latitude, longitude, and elevation. I keep getting the following two errors:
Error using surf (line 71)
Z must be a matrix, not a scalar or vector.
Error in (line 49)
surf(A);
>>
  3 个评论
Stephen23
Stephen23 2020-4-5
Original function by Paul Ramirez, from Google Cache:
"Understanding how to use the function griddata"
graph = xlsread('Path3.xlsx');
x=graph(:,1);
y=graph(:,2);
z=graph(:,3);
[X,Y]= meshgrid(x,y);
Z = griddata(x,y,z,X,Y);
A = mesh(X,Y,Z);
hold on
surf(A);
hold off
xlabel('x'),ylabel('y'),zlabel('z'),title('title')
I have an excel file which I have imported with latitude, longitude and elevation in 3 columns. I'm trying to use the function meshgrid with the latitude and longitude values, and then the function griddata to fit the elevation data points to the meshgrid to develop a surface plot for latitude, longitude, and elevation. I keep getting the following two errors:
Error using surf (line 71)
Z must be a matrix, not a scalar or vector.
Error in (line 49)
surf(A);
>>

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2020-4-5
graph = xlsread('Path3.xlsx');
x=graph(:,1);
y=graph(:,2);
z=graph(:,3);
[X,Y]= meshgrid(x,y);
Z = griddata(x,y,z,X,Y);
surf(X, Y, Z); %includes edges such as would be drawn by mesh()
xlabel('x'),ylabel('y'),zlabel('z'),title('title')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by