3.5

3.5 | 2 ratings Rate this file 9 Downloads (last 30 days) File Size: 1.64 KB File ID: #25277
image thumbnail

xyzplotter

by Jack Kohoutek

 

10 Sep 2009 (Updated 21 Sep 2009)

Transforms lists xin,yin,zin into matrices which can be used with the functions surf and mesh.

| Watch this File

File Information
Description

MATLABs most commonly used 3-d plotting tools surf and mesh require rectangular grids to plot in 3-d, not x,y,z triples. This function converts arrays of x,y,z triples into rectangular grids to use with surf, mesh, etc.

common usage:
[x y z] = xyzplotter(xin,yin,zin)

xin,yin,zin are n x 1 arrays that define your surface. So xin(1),yin(1),zin(1) is the first point in your surface, etc. They do not need to be in any particular order.

Missing values in the grid will be filled in with NaNs. If you would like to interpolate the NaNs, I suggest inpaint_nans, file exchange number 4551. Here is the link:
http://www.mathworks.com/matlabcentral/fileexchange/4551

Andrew Stephens contributed some good ideas to this code, mostly accumarray() and unique() which I didn't know existed before. For now I would like to acknowledge his generous contribution.

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
10 Sep 2009 Andrew Stevens

This code worked fine for the example that I tried. Here are a couple comments and questions that I think, if addressed, will improve the code and clarify its function.

1)The help section is in a non-standard format and an H1 line would be useful.
2) What does the code do with repeat x and y values?
3) What is the cell-size of the resulting grid? Answers to 2 and 3 should be added to the help section.
4) Efficiency: This code uses a triple loop to fill the grid. For large datasets, this will be extremely slow. An alternative approach is to use a combination of HISTC and ACCUMARRAY to populate the grid that will be fast.

-Andrew

16 Sep 2009 Jack Kohoutek

I have a version running that uses accumarray as mentioned instead of the triple loop to fill the grid. However, the current result is that it takes 50 ms longer (out of 500) to run on my 3000 element test dataset. If anyone has a huge dataset they would like to send me to try with it, say, 10^5 elements or so, I would like to do that first since the method is a little less straightforward to follow in the code. I don't know what the demand is for datasets this large either. My email can be found in my profile.

25 Apr 2010 Andrew

Thank you! What a silly omission by Matlab not to have a function that does this. Considering Matlab is mostly for people with data to crunch, and that x,y,z format is pretty common, it's hardly even spoken about in the help files. One overly involved method is to use meshgrid and griddata.m, and that crashes if you don't want a new x,y data grid.

Please login to add a comment or rating.
Updates
14 Sep 2009

Addressed numbers 1-3 of the first comment. Thank you very much for the rating and feedback!

21 Sep 2009

Updated code for a very large speed increase with more random datasets, thanks to some help from Andrew Stephens.

Tag Activity for this File
Tag Applied By Date/Time
image processing Jack Kohoutek 10 Sep 2009 12:54:50
mathematics Jack Kohoutek 10 Sep 2009 12:54:51
signal processing Jack Kohoutek 10 Sep 2009 12:54:51
data exploration Jack Kohoutek 10 Sep 2009 12:54:51
3d plotting Jack Kohoutek 10 Sep 2009 12:54:51
modeling Jack Kohoutek 10 Sep 2009 12:54:51
interpolation Jack Kohoutek 10 Sep 2009 12:54:51
modeling Arash 22 Oct 2011 23:10:26

Contact us at files@mathworks.com