Having trouble making a surface plot using data from Excel

조회 수: 1 (최근 30일)
Henrik Caroe
Henrik Caroe 2021년 4월 3일
댓글: Henrik Caroe 2021년 4월 4일
Im trying to construct a surface plot of a mountain using MATLAB. I've been trying to import data from Excel but when trying to use the script:
function plot3Ddata(x,y,z)
data = xlsread('TamElev2','A2:C261');
x=data(:,1);
y=abs(data(:,2));
z=data(:,3);
dt = delaunayTriangulation(x,y);
tri= dt.ConnectivityList;
xi= dt.Points(:,1);
yi= dt.Points(:,2);
F= scatteredInterpolant(x,y,z);
zi=F(xi,yi);
trisurf(tri,xi,yi,zi);
end
It keeps giving me a flat line going in both the x and y direction, I'm not sure if it is an issue with my code or how I have the data set up in excel but no matter what I do, it hasn't been plotting nicely.
  댓글 수: 2
KSSV
KSSV 2021년 4월 4일
Attach your data.
Henrik Caroe
Henrik Caroe 2021년 4월 4일
TamElev2 is a set of data I generated online, and the set I've been attempting to use with no luck. TamElev3 is a set of data I collected myself.

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

답변 (1개)

darova
darova 2021년 4월 4일
Either use triangulation
x = rand(20,1);
y = rand(20,1);
z = rand(20,1);
dt = delaunay(x,y);
trisurf(dt,x,y,z)
Either griddata
x = rand(20,1);
y = rand(20,1);
z = rand(20,1);
x1 = linspace(min(x),max(x),20);
y1 = linspace(min(y),max(y),20);
[X,Y] = meshgrid(x1,y1);
Z = griddata(x,y,z,X,Y);
surf(X,Y,Z)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by