Lists and Indexing edit page

One key idea of MTEX is that variables may represent list of multiple objects of the same kind. To name just a few: a variable of type EBSD represents a list of EBSD measurements, a variable of type grain2d represents a list of grains and grains.boundary represents the list of all boundary segments of these grains. The next key idea is that a function applied to a list of something operates on each element individually and returns a list of results with the same size as the input list, e.g.

grains.area

will return a list of grain areas for each grain in the list grains. In this section we will briefly explain the general syntax of working with lists or arrays as they are called by Matlab. For more details have a look at the Matlab documentation.

Setting up a list

x = [1,2,3,4,5,6]
x =
     1     2     3     4     5     6
x = 1:10
x =
     1     2     3     4     5     6     7     8     9    10
y = x.^2
y =
     1     4     9    16    25    36    49    64    81   100

Direct Indexing

ind = [1,3,5]
y(ind)
ind =
     1     3     5
ans =
     1     9    25

Logical Indexing

% set up a condition that checks every element of x whether it is even or not
cond = iseven(x)

% extract on the elements of x that satisfy this condition
y(cond)
cond =
  1×10 logical array
   0   1   0   1   0   1   0   1   0   1
ans =
     4    16    36    64   100