[MATLAB logo] Exploiting MATLAB's Data Structures

Comma-separated Lists

Usage: Vectorize manipulation of cell arrays.

Examples:

by itself, for display
concatenation with [ ]
creating cell arrays with { }
function input/output arguments
 
The function fftshift uses comma-separated list expansion for the indexing expression on the last line. This allows fftshift to use N subscripts for an N-D input. Without comma-separated list expansion, fftshift would have to use eval or a switch statement that handles some range of input sizes.
function y = fftshift(x)
%FFTSHIFT Shift DC component to center of spectrum.
%   For vectors, FFTSHIFT(X) swaps the left and right halves of
%   X.  For matrices, FFTSHIFT(X) swaps the first and third
%   quadrants and the second and fourth quadrants.  For N-D
%   arrays, FFTSHIFT(X) swaps "half-spaces" of X along each
%   dimension.
%
%   FFTSHIFT is useful for visualizing the Fourier transform with
%   the DC component in the middle of the spectrum.
%
%   See also FFT, FFT2, FFTN.

%   J.N. Little 6-23-86
%   Revised for N-D by Steve Eddins, February 1997
%   Copyright (c) 1984-97 by The MathWorks, Inc.
%   $Revision: 5.2 $  $Date: 1997/02/28 20:39:48 $

numDims = ndims(x);
idx = cell(1, numDims);
for k = 1:numDims
    m = size(x, k);
    p = ceil(m/2);
    idx{k} = [p+1:m 1:p];
end

% Use comma-separated list syntax for N-D indexing.
y = x(idx{:});

Copyright © 1997 The MathWorks, Inc.
clay@mathworks.com
$Revision$ $Date$