MATLAB: How to plot 3D using a txt file

3d plotserrorMATLABmeshplotsurf

I want the following graph
I tried using mesh and surf it is showing error that data should be matrix not scalar my txt file is attached below please help me solve this

Best Answer

I assume that first 3 columns are x, y, and z values. You need to use scatteredInterpolant
data = readmatrix('chalitp.txt');
x = data(:,1);
y = data(:,2);
z = data(:,3);
f = scatteredInterpolant(x, y, z);
xg = linspace(min(x), max(x), 20);
yg = linspace(min(y), max(y), 20);
[Xg, Yg] = meshgrid(xg, yg);
Zg = f(Xg, Yg);
surf(Xg, Yg, Zg);
Related Question