Please enable JavaScript to view this site.

Knowledge Base

Creates a cell array variable with specified number of elements. The cell array element can be any data type, such as matrix, string, and dataset.

 

Supported Product: FDTD, MODE, DEVICE, INTERCONNECT

 

Syntax

Description

a = cell(n);

Creates a cell array with n elements.

a{n} = "string";

Adds a string to the specified element of the cell array.

a{n} = matrix(5,5);

Adds a field of matrix of 5x5 to the specified element of the cell array.

 

 

Examples

In the below example, a cell array variable is created and to its elements, a dataset is assigned.

b = cell(2);   # initialize 2 element cell array

b{1} = [1,2,3]; # store a 3 element vector in the first cell of the cell array

b{2} = "string"; # store a string in the second cell of the cell array

?b{1};      # print the contents of the first cell to the screen

?b{2};      # print the contents of the second cell to the screen

?b{1}(1);    # print the first element of the vector within the first cell to the screen

result: 

1 2 3 

string

result: 

 

a = struct;

a.a = getresult("monitor","T");

?a.a;

T vs lambda/f

 

b{1} = a;

?b{1};

Struct with fields:

a

?b{1}.a;

T vs lambda/f

 

b{2} = struct;

b{2}.a = matrix(5,5);

b{2}.b = 1;

b{2}.c = cell(2);

b{2}.c{1} = 3.14;

b{2}.c{2} = 6.28;

 

This example shows how to create an array of strings.

N=10;

fnames = cell(N);

for ( i=1:N) {

 fname="file_"+num2str(i);

 save(fname);

 fnames{i} = fname;

}

 

?fnames{3};

file_3

?fnames{10};

file_10

 

See Also

Datasets, matrixdataset, rectilineardataset, struct, splitstring

Copyright Lumerical Inc. | Privacy | Site Map