Programming  Comma-Separated Lists

Typing in a series of numbers separated by commas gives you what is called a comma-separated list. MATLAB returns each value individually:

• ```1, 2, 3
ans =
1
ans =
2
ans =
3
```

Such a list, by itself, is not very useful. But when used with large and more complex data structures like MATLAB structures and cell arrays, the comma-separated list can enable you to simplify your MATLAB code.

This section covers

Generating a List from a Cell Array

Extracting multiple elements from a cell array yields a comma-separated list. Given a 4-by-6 cell array as shown here

• ```C = cell(4, 6);
for k = 1:24,   C{k} = k * 2;   end

C
C =
                    
                    
                    
                    
```

extracting the fifth column generates the following comma-separated list:

• ```C{:, 5}
ans =
34
ans =
36
ans =
38
ans =
40
```

This is the same as explicitly typing

• ```C{1, 5}, C{2, 5}, C{3, 5}, C{4, 5}
``` Operator Summary Generating a List from a Structure © 1994-2005 The MathWorks, Inc.