source: MML/trunk/machine/SOLEIL/common/disperse.m

Last change on this file was 17, checked in by zhangj, 10 years ago

To have a stable version on the server.

  • Property svn:executable set to *
File size: 1.0 KB
Line 
1function varargout = disperse(x)
2% DISPERSE was created so that you can stop doing things like this:
3%
4%   x1 = array(1); % ...repetitive assignments from an array
5%   x2 = array(2);
6%   x3 = array(3);
7%   x4 = array(4);
8%
9% and start doing things like this:
10%
11%   [x1 x2 x3 x4] = disperse(array);
12%
13% DISPERSE generalizes to arbitrary dimensions, and is extended to follow
14% analogous behavior on cell arrays and structure arrays. See the html
15% documentation for more details and examples.
16%
17% Example:
18%   Grab the color channels from an RGB image:
19%   [r g b] = disperse(im);
20
21% Sam Hallman
22% shallman@uci.edu
23% May 26, 2010
24
25% num2cell on column vectors is problematic
26if ndims(x)==2 && size(x,2)==1
27    x = x';
28end
29
30if isnumeric(x) || ischar(x) || islogical(x) || isstruct(x)
31    dims = 1:ndims(x)-1;
32    varargout = num2cell(x,dims);
33elseif iscell(x)
34    if size(x,1) == 1
35        varargout = x;
36    else
37        dims = 1:ndims(x)-1;
38        varargout = num2cell(x,dims);
39    end
40else
41    error('unknown data type');
42end
Note: See TracBrowser for help on using the repository browser.