File Exchange

image thumbnail

Making Surface Plots From Scatter Data

version (92 KB) by Zain Mecklai
How to turn a collection of XYZ triplets into a surface plot.


Updated 01 Sep 2016

View License

Editor's Note: This file was a File Exchange Pick of the Week

How do you turn a collection of XYZ triplets into a surface plot? This is the most frequently asked 3D plotting question that I got when I was in Tech Support. This submission explains how.

Cite As

Zain Mecklai (2020). Making Surface Plots From Scatter Data (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (83)

Zhen Kok

Colin Burn

Excellent work!!! I've spent days trying to do this.


Thank you very much. Hope can combine such figures with CST.

Only works well if the layered Z planes do not have very close x,y corrodinates. Mine have, the results make triangles that connects to z far away, just because it is close in xy.

not possible to smooth it ?

Lido Ju

Mengsi Gao

Perfect! This should be part of the software!

no help

Excellent post. Is there a similar function, or set of steps to calculate gradients on scatter data from X, Y, Z triplets?

Pi Ting

thanks a lot

thank you very much!!

Frank Riley

Thanks for the tip, works perfectly.

Laura Paez


Lifesaver, cheers. For me it really helped getting rid of the "clean it up" section at the bottom



It does not work for a sphere.

Awesome!!! Thanks!

Iddo Weiner


Beth Wilcox




Liye SUN

Works Well!

Very helpful!

Sarah Olson

So helpful!

E. Cheynet

Ali Ghayoor


Jang DV

Excellent !

Roman Jamy

Asa Darnell

A+. I'm using this to visualize data from a Photogrammetry software that outputs 'random' data points instead of points on a standard grid and it works perfectly! Thanks!!!!!!!!


Great function, helped a lot for creating lookuptables.

This is exactly what I've been looking for for years. Worked great.



very helpful thanks a lot

But this doesn't work when a surface is curved like a ball. You triangulate these projections of the vertices on x-y plane, but some obtained triangles are not the projections of the real triangles on the surface.



just what i needed!!!!

thanks, solved my problem as well

Manel Soria

Thanks !


Excellent. Well done!

IIT Bombay

extremely useful


Awesome!! Can anybody tell if I can draw contour plot on the same?


C. Maguire

Using "delaunay" is what "griddata" does. It's only okay for 2D data, but very slow for 3D data (z will be an individual dimension, instead of a value of f(x,y) in 3D data situation). Because of this reason, "griddata3" is good but too slow.

Carlos Adrian Vargas Aguilera

This is nice Zain. Why don't you made a function? Ignoring NaNs also.

Thomas Jansson

Just what I was looking for - this should have a seperate function in Matlab or at least be listed in the help files. :)

Laura .

Works great!

Johnny Green

Thanks so much!

Catherine St-P

Thank you!!! It saved me sooo much time! Wow...

jack zuo

good stuff!

Jen Badham

Just what I needed

Xiaolan Wang

Genius idea. Easy and works just perfectly. Thank you very much.

Blake Fleischer

Being new to this program, the tutorial was essential for me. Only problem I had was typing the right commands. Many Thanks!

Oya Mercan



Nimal L


quite good!

Chris Lim

Any idea on how to make a contour plot with scatter data?

sheela kumar

cool !

Chammika Udalagama

Goncalo Gil

Sweet!!! That did it!

remove [NOSPAM!!!] from email if you would like to contact me.

Eric Benson

Solved my problem!

Robert Riley

Lorenzo Natale

Stefan Burger


Updated license

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux