How to do surface plot from given set of data?

I have X and Y and Z coordinates. Now i want ro do surface plot of these data, I used surf() command but its showing error. can anyone give idea how can i plot the data. I have add data for the reference.

댓글 수: 2

Z must be a matrix
if the values x,y,and z is a coordinates of point i think we shoud use 3d plot instead of surface or used this line
load Data.txt % after we remove the chararcter from the txt file
surf(data);

댓글을 달려면 로그인하십시오.

 채택된 답변

KSSV
KSSV 2022년 3월 31일
편집: KSSV 2022년 3월 31일

0 개 추천

T = readtable('data.txt') ;
x = T.(1) ;
y = T.(2) ;
z = T.(3) ;
% Plot as unstructured grid
dt = delaunayTriangulation(x,y) ;
p = dt.Points ;
tri = dt.ConnectivityList ;
F = scatteredInterpolant(x,y,z) ;
z = F(p(:,1),p(:,2)) ;
figure(1)
trisurf(tri,p(:,1),p(:,2),z)
view(2)
shading interp
% Plot as structured grid
xi = linspace(min(x),max(x),300) ;
yi = linspace(min(y),max(y),300) ;
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
figure(2)
pcolor(X,Y,Z) ;
shading interp

댓글 수: 4

There is a error in 'z' values while computing 'z' size of z i m getting is 291x1 but the size of 'x' and 'y' are 341z1. To plot all value should be of same size.
error is like this
Error using griddata (line 106)
X and Y must be same length as Z or the lengths of X and Y must match
the size of Z.
I am not getting any error.....Show us the code you have tried.
I think you have copied the given answer and tried. It has over written the variable z. Use the below code:
T = readtable('data.txt') ;
x = T.(1) ;
y = T.(2) ;
z = T.(3) ;
xi = linspace(min(x),max(x),300) ;
yi = linspace(min(y),max(y),300) ;
[X,Y] = meshgrid(xi,yi) ;
Z = griddata(x,y,z,X,Y) ;
pcolor(X,Y,Z) ;
shading interp
I just copied the above code and just do change in load data. other i kept as it is but showing error but the second code works fine.
Thank you for the help.
KSSV
KSSV 2022년 3월 31일
Thanks is accepting/ voting the answer.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

질문:

2022년 3월 31일

댓글:

2022년 3월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by