This video is taken from the Scripting Learning Track on Ansys Innovation Courses.
Transcript
To initialize a string variable, you just need to use the “=“ operator.
You can use single or double quotes to create a string.
Arrays can be initialized in various ways.
You can assign values directly using [ ]. Use , to separate columns and ; to separate
rows (highlight M=…).
You can use the array operator “:” to create a series of number.
N=2:5 will create an array of numbers from 2 to 5 with an increment of 1.
O=10:-1.5:5; will create an array of numbers starting at 10, with consecutive elements
decreasing by 1.5.
All elements will be >=5.
You can use the “linspace” command to create an array of numbers linearly spaced
going from min to max with n elements: P=linspace(4,9,4); will create an array of 4 numbers, linearly
spaced between 4 and 9.
You can use the “matrix” and the “zeros” functions to create an array filled with 0.
Or you can Use the “ones” function to create an array filled with ones.
Arrays’ elements can be accessed using their index.
Note the index starts at 1 and not 0.
To create a structure array, use the “struct” command.
Then you can add and access the structure array’s elements using the “.” operator.
Similarly, to create a cell array, use the ‘cell’ command and specify the number
of elements.
The elements can be accessed using { } and the index of the element.