Selecting Grains edit page

In this section we discuss how to select grains by properties. We start our discussion by reconstructing the grain structure from a sample EBSD data set.

## Selecting grains by mouse

The most easiest way to select a grain is by using the mouse and the command selectInteractive which allows you to select an arbitrary amount of grains. The index of the selected grains appear as the global variable indSelected in your workspace

## Indexing by orientation or position

One can also to select a grain by spatial coordinates without user interaction. This is done using the syntax grains(x,y), i.e.,

Alternatively one can also select all grains with a certain orientation. Lets find all grains with a similar orientation as the one marked in gold. As threshold we shall use 20 degree

## Indexing by a Property

In order the generalize the above concept lets remember that the variable grains is essentially a large vector of grains. Thus when applying a function like area to this variable we obtain a vector of the same lenght with numbers representing the area of each grain

As a first rather simple application we could colorize the grains according to their area, i.e., according to the numbers stored in grain_area

As a second application, we can ask for the largest grain within our data set. The maximum value and its position within a vector are found by the Matlab command max.

The number max_id is the position of the grain with a maximum area within the variable grains. We can access this specific grain by direct indexing

and so we can plot it

Note that this way of addressing individual grains can be generalized to many grains. E.g. assume we are interested in the largest 5 grains. Then we can sort the vector grain_area and take the indices of the 5 largest grains.

## Indexing by a Condition

By the same syntax as above we can also single out grains that satisfy a certain condition. I.e., to access are grains that are at least one quarter as large as the largest grain we can do

This is a very powerful way of accessing grains as the condition can be build up using any grain property. As an example let us consider the phase. The phase of the first five grains we get by

Now we can access or grains of the first phase Forsterite by the condition

To make the above more directly you can use the mineral name for indexing

Logical indexing allows also for more complex queries, e.g. selecting all grains perimeter larger than 6000 and at least 600 measurements within

## The grainId and how to select EBSD inside specific grains

Besides, the list of grains the command calcGrains returns also two other output arguments.

The second output argument grainId is a list with the same size as the EBSD measurements that stores for each measurement the corresponding grainId. The above syntax stores this list directly inside the ebsd variable. This enables MTEX to select EBSD data by grains. The following command returns all the EBSD data that belong to grain number 33.

and is equivalent to the command

The following picture plots the largest grains together with its individual orientation measurements.

## Boundary grains

Sometimes it is desirable to remove all boundary grains as they might distort grain statistics. To do so one should remember that each grain boundary has a property grainId which stores the ids of the neigbouring grains. In the case of an outer grain boundary, one of the neighbouring grains has the id zero. We can filter out all these boundary segments by

Now grains.boundary(outerBoundary_id).grainId is a list of grain ids where the first column is zero, indicating the outer boundary, and the second column contains the id of the boundary grain. Hence, it remains to remove all grains with these ids.

finally, we could remove the boundary grains by

However, boundary grains can be selected more easily be the command isBoundary.