Regridding unequally spaced sampled field, and plotting an imagesc

| categories: matlab, octave | View Comments

In a previous post we discussed a better way for using imagesc, with a more sane colormap. Let's now speak about the grid. Imagesc will happily embed every xy-axis you plug in, without checking whether dimensions fit. If your grid is non-equally spaced - it will just draw the z-axis on a regular axis (i.e. ignoring the xy input), and show the xy-axes as if they genuinely represent the input. My conclusion from this wild behavior is - never use imagesc on non-equally spaced data. Matlab has nice interpolant interfaces to help you get your data equally gridded.

1: [x1,y1]=ndgrid(x,y); % this step is actually not crucial
2: I = griddedInterpolant(x1,y1,z);  
3: x1 = linspace(min(x),max(x),5);     % Define an equally spaced grid
4: y1 = linspace(min(y),max(y),5);
5: [x1,y1]=ndgrid(x1,y1);
6: z1=I(x1,y1);
7: myimagesc(x1(1,:),y1(:,1),z1,0.55,0.95,0.05);

Where your input parameters to myimagesc may vary, and you could replace "5" by whatever division of the equally spaced grids you fancy.

Copyright (C) 2015 by Avi Gozolchiani. See the License for information about copying.

org-mode source

blog comments powered by Disqus