Be the first to rate this file! 196 downloads (last 30 days) File Size: 2.87 KB File ID: #23479

BIN2MAT

by Andrew Stevens

 

30 Mar 2009 (Updated 01 Apr 2009)

No BSD License  

Create a matrix from scattered data without interpolation

Download Now | Watch this File

File Information
Description

BIN2MAT can be used to create a grid from scattered 2D data using grid-cell averaging (no interpolation). BIN2MAT also accepts function handles so you can evaluate many different functions over each grid cell. If the specified function returns non-scalar output, BIN2MAT will return a cell array.

EXAMPLE (generates screen-shot)

 %generate some scattered data
     [x,y,z]=peaks(150);
     ind=(rand(size(x))>0.9);
     xs=x(ind); ys=y(ind); zs=z(ind);
 
%create a grid
     xi=min(xs):0.25:max(xs);
     yi=min(ys):0.25:max(ys);
     [XI,YI]=meshgrid(xi,yi);
 
%calculate the mean and standard deviation
%for each grid-cell using bin2mat
     Zm=bin2mat(xs,ys,zs,XI,YI); %mean
     Zs=bin2mat(xs,ys,zs,XI,YI,@std); %std
   
%plot the results
     figure
     subplot(1,3,1);
     scatter(xs,ys,10,zs,'filled')
     axis image
     title('Scatter Data')
 
     subplot(1,3,2);
     pcolor(XI,YI,Zm)
     shading flat
     axis image
     title('Grid-cell Average')
 
     subplot(1,3,3);
     pcolor(XI,YI,Zs)
     shading flat
     axis image
     title('Grid-cell Std. Dev.')

MATLAB release MATLAB 7.8 (R2009a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Updates
01 Apr 2009

modified error-checking, also add a check to make sure x,y,z inputs are column (m x 1) vectors.

Tag Activity for this File
Tag Applied By Date/Time
reshape Andrew Stevens 30 Mar 2009 11:19:13
vector Andrew Stevens 30 Mar 2009 11:19:13
gridding Andrew Stevens 30 Mar 2009 11:19:13
accumarray Andrew Stevens 30 Mar 2009 11:19:13
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com