# Understanding how to use the function griddata

조회 수: 9(최근 30일)
Priscilla Ramirez 5 Apr 2020
댓글: Rena Berman 14 May 2020 16:08
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

Geoff Hayes 5 Apr 2020
Paul - what is A? Is that the handle to or the chart surface object returned by the call to mesh? Should you be calling surf(X,Y,Z) instead?
Stephen Cobeldick 5 Apr 2020
Original function by Paul Ramirez, from Google Cache:
"Understanding how to use the function griddata"
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);
>>
Rena Berman 14 May 2020 16:08

로그인 to comment.

### 채택된 답변

Walter Roberson 5 Apr 2020
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')

로그인 to comment.

### 추가 답변(0개)

이 질문에 답변하려면 로그인을(를) 수행하십시오.

Translated by