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.
Since Lumerical 2019b R4 version, users can also declare a cell by using the braces and square brackets declaration method.
Syntax |
Description |
---|---|
a = {"a", "b", 1, 2.3} |
Creates and initializes a cell array. |
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
A cell can be created and initialized quickly as follows:
myCell = {"a", "b", 1, 2.3};
# cell with struct
myCellWithStruct = {"a", {"b" : 2, "c" : 3}};
The above cell can also be declared more pedantically:
myCell = cell(4);
myCell{1} = "a";
myCell{2} = "b";
myCell{3} = 1;
myCell{4} = 2.3;
# cell with struct
myCellWithStruct = cell(2);
myCellWithStruct{1} = "a";
myCellWithStruct{2} = struct;
myCellWithStruct{2}.b = 2;
myCellWithStruct{2}.c = 3;
The above declaration methods are equivalent and will produce the same output:
?myCell;
Cell array with 4 elements
?myCell{1};
a
?myCellWithStruct;
Cell array with 2 elements
?myCellWithStruct{1};
a
?myCellWithStruct{2};
Struct with fields:
b
c
?myCellWithStruct{2}.b;
result:
2
When two or more objects have similar properties, such as spacial location of "x" and "y", one can define a "cell" with "x" and "y", and get their values:
propxy = {"x","y"};
out1 = getnamed("rectangle",propxy);
out2 = getnamed("monitor",propxy);
?out1.x;
?out2.y;
In the above example, geometry "rectangle" and monitor "monitor" both have "x" and "y" properties.
See Also
Datasets, matrixdataset, rectilineardataset, struct, splitstring