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

Citing this page. This page is part of the documentation of MTEX, a free and open source MATLAB toolbox for analyzing and modeling crystallographic textures. It was written by The MTEX Developers and is published at https://mtex-toolbox.github.io/ListsAndIndexing.html. If you use MTEX, or reuse text or figures from this page, in your research, please cite

F. Bachmann, R. Hielscher, H. Schaeben: Texture Analysis with MTEX - Free and Open Source Software Toolbox, Solid State Phenomena 160 (2010), 63-68. 10.4028/www.scientific.net/SSP.160.63

BibTeX
@article{bachmann2010mtex,
  author  = {F. Bachmann and R. Hielscher and H. Schaeben},
  title   = {Texture Analysis with MTEX - Free and Open Source Software Toolbox},
  journal = {Solid State Phenomena},
  volume  = {160},
  pages   = {63-68},
  year    = {2010},
  doi     = {10.4028/www.scientific.net/SSP.160.63},
  url     = {https://doi.org/10.4028/www.scientific.net/SSP.160.63}
}

Other papers describing specific MTEX methods are listed under Publications — please cite the one that best fits your application. The MTEX source code is licensed under the GNU General Public License v2.0; the text and figures of this documentation are licensed under CC BY 4.0, which permits reuse — including by automated systems — provided The MTEX Developers and this page are credited.