Displays the output of the command on the screen This function does not return any data.
?(5+5);
result:
10
?"file_"+"name_"+num2str(1);
file_name_1
?1:2001;
matrices of length greater than 2000 are not displayed to the output
?num2str(1:2001)
1
2
3
⋮
2000
2001
2. : 用于表示数组
: (array operator, colon)
syntax
Description
x = 2 : 10;
x will be an array of numbers that start at 2 and increase by 1 for each consecutive number. The last entry will be <= 10. x will equal 2,3,…,9,10.
x = 6 : -1.5 : 2;
x will be the array were the first element is 6, and consecutive elements decrease by 1.5. All elements will be >=2. In this example, the array will be [6, 4.5, 3].
B=A(:, 2)
B will be the array containing all the elements from the second dimension of A.
a=l:5; # a will be vector (1, 2, 3, 4, 5)
?b=a(4:-1:2); # b will be vector (4, 3, 2)
a=[1,2,3;4,5,6];
?b=a(:, 1); # b will be vector (1, 4)
3. ^ 用于表示指数
^ (exponent, power, caret)
Syntax
Description
y = x^3;
x cubed.
x=1:3;
y=2:4;
?z=x^y;
result:
1
8
81
NOTE: In expression A^B, if B is complex, the phase of A is evaluated from
−
π
-\pi
−π to
π
\pi
π.
4. % 用于表示带空格的变量名
Command
Description
%variable with space%
To create a variable name that contains spaces, such as “variable with space”, put a percentage sign before and after the variable name.
%variable with space%=2;
?%variable with space%*3;
result:
6
%x span% = get("x span");
?%x span% * 1e6; # x span in um
result:
4.8
5. # 注释
# (comment, sharp, hashtag, pound)
Syntax
Description
x=1; # set x to 1
Anything after the # character is ignored.
?"this string contains a # symbol";
6. . 从数据集中获取参数和属性
. (dataset dot)
Syntax
Description
result = A.result;
Retrieves the parameter or attribute “result” from the existing dataset A. The result is a scalar matrix.
E = getresult("profile","E");
f = E.getparameter("f"); # the parameter f
Ex = E.getattribute("Ex"); # the x component of the electric field
E2 = E.getattribute("E2"); # the electric field intensity, note that this only works if E is a vector
E = getresult("profile","E");
f = E.f; # the parameter f
Ex = E.Ex; # the x component of the electric field
E2 = E.E2; # the electric field intensity, note that this only works if E is a vector
7. almostequal 用于浮点数判断相等
Syntax
Description
out = almostequal(A, B);
Returns 1 if |A - B| is less than or equal to |A + B|/2*1e-15. Returns 0 otherwise.
out = almostequal(A, B, relative diff);
Returns 1 if |A - B| is less than or equal to |A + B|/2 times relative diff. Returns 0 otherwise.
out = almostequal(A, B, relative diff, absolute diff);
Returns 1 if |A - B| is less than or equal to |A + B|/2 times relative diff or if |A - B| is less than or equal to absolute diff. Returns 0 otherwise.
Create an N by M matrix. Columns are separated with semicolons. Elements in a row are separated with commas. The entries can either be scalars or matrices of compatible dimension.
Runs the block of commands. If an error occurs, the error message is displayed and the script continues.
try {Command1;Command2:…} catch(errMsg);
Runs the block of commands. If an error occurs, the error message is stored in the variable “errMsg” and the script continues.
a=1;
try {
?C;
}
?a;
Error: prompt line 3: C is not a valid function or variable name
Result:
1
a=1;
try {
?C;
} catch(errMsg);
?a;
?errMsg;
Result:
1
Error: prompt line 3, C is not a valid function or variable name
1.3 循环
for
Syntax
Description
for(x=1:100) { ?x; }
Single argument for loop. The loop will be sequentially executed for each value of x.
for(x=1; x<= 100; x=x+1) {?x;}
Three argument for loop.x=1 at the start of the loop. The loop continues while x <=100 and sets x=x+1 at each pass.
x=1;for(0; x<10; 0) {?x;x=x+1;}
This is equivalent to a while loop that will execute
a=1:2:10;
for(x=a) {
?x;
}
for(i=1:100) {
for(j=1:100) {
x(i,j) = i^2+j;
?x;
}
}
run;
mNames = splitstring(getresult,endl);
for (i=1:length(mNames)) {
if (haveresult(mNames{i},"E")) {
E=getresult(mNames{i},"E"); # get a result from that monitor
} else {
E = mNames{i} + " did not contain the specified data.";
}
savedata(mNames{i},E); # save data to file
}
# implementation of a while loop in languages that support while loops
x=1;
while(x<10) {
?x;
x=x+1;
}
# equivalent implementation of a while loop in Lumerical script language
x=1;
for(0; x<10; 0) {
?x;
x=x+1;
}