Main Content

curly braces, { }

Cell array creation, indexing

Syntax

Description

Curly braces {} create and index cell arrays, and also index data in tables and timetables. For instance, T{rows,vars} returns an array of concatenated data from the specified rows and variables of a table or timetable.

example

Examples

expand all

Use curly braces to create a cell array with three cells of data, and then index one of the cells.

C = {[2.6 4.7 3.9], rand(8)*6, "myString"}
C=1×3 cell array
    {[2.6000 4.7000 3.9000]}    {8x8 double}    {["myString"]}

C{1,3}
ans = 
"myString"

Use curly brace indexing to access data in a table.

Create a table with three variables, and then index the first row of data across all variables.

T = table((1:4)',5*ones(4,1),2*ones(4,1))
T=4×3 table
    Var1    Var2    Var3
    ____    ____    ____

     1       5       2  
     2       5       2  
     3       5       2  
     4       5       2  

T{1,:}
ans = 1×3

     1     5     2

Version History

Introduced before R2006a