Matlab code snippets

ndgrid vs repmat

% get coodinates of points on a grid within a sphere
r=5; % 5 voxels radius
circle_points=[repmat([-r:r]',(2*r)^2,1) reshape(repmat(-r:r,2*r,2*r),(2*r)^3, 1) reshape(repmat(-r:r,(2*r)^3,1),(2*r)^3,1)];
%% the above statement can be simplified as:
circle_points=reshape(cat(4, x, y, z),(2*r+1)^3,3);
% remove points that are out of the radius range
matlab.txt ยท Last modified: 14.08.2010 00:16 by
Recent changes RSS feed Creative Commons License Valid XHTML 1.0 Valid CSS Driven by DokuWiki
Drupal Garland Theme for Dokuwiki