Technical ReportPDF Available

Getting Started with MTEX for EBSD analysis Rev6

Authors:
  • Kingston Process Metallurgy

Abstract

This manual is aimed at quickly teaching new MTEX users how to correctly do EBSD texture analysis to produce EBSD maps and pole figures. It will also provide a reference for intermediate users, and advice on verifying the accuracy of your EBSD maps. It is intended to be simple, direct, and accessible to users of all backgrounds with many examples and images.


 !!"#$#"%"%
 &'(&)
&) *
+ &',
 
!!"
####
-. ((&'''&
((''(&/
$%##
%!&!'()
#0
"*+,#"-.-/!&
#*/0'+('1$
/!234.!
#
5!#
!1
6"*+#-"*+
"-.-/7
"*+

6#
1,#!"*+

#
#  1*/0'
#(0
8 9:#;33,
##3
< 9!;33#3,#33
= &-9*(5>?-@**4*'$0'>?"*-'
*6*/
A 9;33#3B0
8CD
Table of Contents
E!;  2
)"*+2
$  F
$>   F
' F
   D
@D
>1C
0# 8G
0"*+,!8G
>$=8G
0'=8G
'88
> 88
08<
0 8=
-: 8=
( 8A
( 82
0, 82
'###8H
"&#8H
0 8H
078F
6!*/0'" 8F
' 8F
 8D
6!*/0'8C
##8C
0I <G
##$9<8
"#<8
"#09 <<
?0 <<
* <<
<=
1#<=
#<A
#=',<A
<2
#<2
<2
<CD
1 <H
0#<F
#<D
#<D
$99<D
.<C
93# <C
7,<C
7, <C
$  =G
*=G
'1#=8
"#=8
 =<
"#=<
#=<
0==
 ==
==
7 ==
0#==
-=A
7*/0'=2
*/0'=2
6!1,=2
0JI&=H
JI=H
)IK =F
I#=F
- =D
'9,1=C
11 =C
>AG
1#AG
1AG
>A<
*1 A<
6! A=
#   AH
=CD
E!;
$CD,
*00*$-.
%
6!@;!!!
%"*+)

?0

$

>##!%

)"*+
#!
#"-.-/##!7
!!%##!#
5#"*+
3
$"*+
'"*+>"-.-/-0
--'"$$0(->(!"-.-/$"-.-/
"*+5
startup_mtex.m startup_mtex"-.-/
$,"*+
#! "*+ %
##!"*+
#$%
"-.-/"*+
>"*+#17
*"*+%
7"-.-/-0--'"$$0(->(
# open mtex_settings.m
ACD
$!"*+#
;
%change the default plotting of the coordinate axes to match my data’s
spatial orientation (about line 30)
setMTEXpref('xAxisDirection','west');
%I usually don't want the micron bar on EBSD maps (line 45)
setMTEXpref('showMicronBar','off')
%I plot PF on multiple planes, so the default annotation is not
helpful and I disable it, by uncommenting line 57 to prevent
annotations
%I prefer less padding on multiple PF (lines 61 and 62)
setMTEXpref('outerPlotSpacing',0);
setMTEXpref('innerPlotSpacing',0);
-''&121(&'
&'3&''' 
$1@+5
1"-.-/
$>
5##&%
%*%
##&
"*+"-.-/0%
!"*+
@;!
*
&"*+
1"&#
#/
&&%

1#1#
1&-
981#
#7
1#*"-.-/#!
1!##
&
$%"*+!
1!
2CD
9
J
- L?!M
N#" )
+ 82GH
5 8=G8
+0 CCCDFA2<A2*,8
50 CCF=2H=8CH*,8
-&*8 G
-&*< G
-&*= G
*00GO " C=*8  8GG ' G 4@
<*8 - FG - G
 8
=<GCI=<GCI2<8 C*8IC*8I8<*< " C 8CA
 + 5 / * *8 *< *= "-' / /0
G GGGGG GGGGG G = GGGGG GGGGG GGGGG GGGGG G <22
G ,GCCCC GGGGG G = GGGGG GGGGG GGGGG GGGGG G <22
G ,8CCCF GGGGG G = GGGGG GGGGG GGGGG GGGGG G <22
G ,<CCCH GGGGG G = GGGGG GGGGG GGGGG GGGGG G <22
G ,=CCC2 GGGGG G = GGGGG GGGGG GGGGG GGGGG G <22
G ,ACCCA GGGGG G = GGGGG GGGGG GGGGG GGGGG G <22
G ,2CCC< GGGGG G = GGGGG GGGGG GGGGG GGGGG G <22
G ,HCCC8 GGGGG G = GGGGG GGGGG GGGGG GGGGG G <22
G ,FCCCG GGGGG G = GGGGG GGGGG GGGGG GGGGG G <22
G ,DCCDC GGGGG G = GGGGG GGGGG GGGGG GGGGG G <22
G ,CCCDF GGGGG G = GGGGG GGGGG GGGGG GGGGG G <22

!!98/!&
77#
,*/0'P171
#7

ebsd=ebsdPADDED('indexed')
!ebsdPADDED
#ebsdN!"-.-/

$%7
#"#

8 !Q*/0'Q!"*+
"-.-/import_wizard('EBSD');
< $#!R#
19<!
= /1"*+
$9=S
%!ST
A $#"9A!ST
2 92
@+5?#
HCD
#!
09H
H @*@*#!

F 0U!#%9F
 # !1



  !

"#$
%&
'
((
)*
+%,-
&-
(&
(
.
/0
&1
ebsd
FCD
@;!
$#!
*/0'#?%
"*+#

$%#&+5
K+5
5K
5$!##V/
/!1(
(&&(20
&&

*&B8B<#9
$!B=A1
B2#%!!
1
8 @+5@+5
< @*/0'*@*
= @#
!*/0'#ebsd.CS)
988
198F
A @
2 @
-#*/0'&#
K0*"P

@+5
0$9&&
*/0'&
"*+5"*+#!  #
09H##
%$#mtexdata
twinsMagnesium#

%create a color map of the IPF orientations of the selected material
oM = ipfHSVKey(ebsd('Magnesium'));
%define the direction of the ipf
oM.inversePoleFigureDirection = xvector;
%convert the ebsd map orientations to a color based on the IPF
DCD
color = oM.orientation2color(ebsd('Magnesium').orientations);
figure; plot(ebsd('Magnesium'),color);
9D;$9+#*/0'
&#/!

9C;$9#"*+
K#
CGWJ

6!#&"*+
%9D9
C9D
98GK
$!+59
+557
!$"*+##
!#
&
"*+
@*
$*/0'&%&!
*KK
!!*>
"*+!*
98G$* 
#CGW'
##-
#CGW*
"*+&
CCD
$%#&CGW!%!!
!
.34,1$4

**#
#K#
'"$(
 '&&4(5&&
4((&
'(15
@;!
1"*+
+5X7
#9
#
,#
,,7,

"*+#
'KJ,#
#

$"*+ebsd#
##ebsd.CSebsd('magnesium').CS
,"
#,#
8GCD
#

3$536
91733
L,8<,8GM33L8G,8GM988
1#
ebsd
%copy the crystal symmetry from the ebsd variable. This variable provides the
relative axes of the unit cell (c/a ratio)
cs=ebsd.CS
%using the crystal symmetry customize the HCP unit cell drawn by the crystal
shape command.
cShape=crystalShape.hex(cs)
%plot the shape
plot(cShape,'figSize','small')
%hold the axes, so the new plot is on top of the old
hold on
%add arrows to the figure along the principal axes, scaled down
arrow3d(0.5*[xvector,yvector,zvector],'labeled')
hold off
%manually set the viewing angle of the plot
set(gca, 'CameraViewAngleMode', 'manual', 'CameraTargetMode', 'manual',
'CameraPositionMode', 'manual');
$"*+K

K98<
csx2a=crystalSymmetry('6/mmm',[3.2,3.2,5.2],'X||a','Z||c')
5*/0'#$
*/0'
transformReferenceFrame
*

88CD
6536
(+%,-
6536
(

0
$#*/0'
0*"#
*/0'$#
*/0'$
98=&
1
K
7(8(,9*&
$:;.(5<
,9*(...=,9*>$
1($....=
8<CD
7*
#*/0'$#
,*/0'K#88Y
%#*/0'#K+5
$%
#0*"1
>,98=
$&%
1"*+#
0-
1"*+
#1#
#
6((
#"*+!
98A9821
%
98A-:
*/0'#%
5"*+#P

 %?
(
?!

"%!
4&1
,9*$
&$(
8=CD
-
61*/0'#
K#
'#
98H1*/0'
#2WK#
#:$%
Z8GG%#!J
K#%
-#
&![&
),9*
(
01
>%#*/0'
%0
%1*1+%79&
 '
save 01#
!#
# .
 
save('foo') 01
!#

8ACD
 &
cd .. or cd('filename') !
1
print('-dtiff','-r500','IPFY') 01
!K
2GG1$95
xlswrite('Foo.xls',variable,'She
etName') *#1
9
strmin =
['Neighbours',num2str(NborNum)];
save(strmin,'StrAccom');
#StrAccom
1
#Neighbours8
%1*+%79(4(
figure 1"*+
1#
hold on
hold off
91
>"*+
close all 1
clear all !#
%1*+%,-
LM\#
L/07#)$'M\0
7
(
$'
#
0"*+
/"*+"-.-/
[##-
%

-!#
#&U9C%
!#%!
$"*+!"-.-/
<#]9
"*+8GW10*degree$"*+

/degree.
,rad2deg(variable)
/degree
82CD
3
"*+9#
mtexdata #1
forsterite!
twins
J!;mtexdata forsterite. 6
##
"*+>"-.-/
1
"*+
0
"*+#!
"$
*='$
 K#
 
0'=
-=5 51,,61
'('(($=1
*/0'77
1
17,
K1=7;
%define the variable v as a vector in the +x,+y direction (bisecting the two
axes)
v = vector3d(1,1,0)
%define r as a vector parallel to the positive x axis of the map.
r= xvector
%define c as a vector3d using combinations of the x and y axis.
c = -xvector + 2*yvector;
>1=;
%convert spherical coordinates to a Cartesian vector.
polarAngle = 60*degree;
azimuthAngle = 45*degree;
%use these angles to create a vector3D. Note the first angle is the angle to
the z axis, while the second is the angle to the x axis.
v = vector3d.byPolar(polarAngle,azimuthAngle)
>=;
hold on
arrow3d(0.5*[xvector,yvector,zvector],'labeled')
8HCD
'"
-"5( 
(&#"1
#3"
##

&#
79
#&,U%8<GWU%
/9
&###
K?K"#
?0
"1
#>"*+
"##
^_#LM`a
$%
1"%

*536+1$
$#%K#
#
98F

$#"",/
#1
"",/1
7",/#
&1
#$#9
##,
1!"*+
22<$!

%1 %++9&
'3 
"$  !
"/ ?@6 4$.
8FCD
91
#"",/J
,17
&!$
1"1
8DCD
%load some ebsd data if necessary
mtexdata twins
%define the crystal symmetry to use, pulling it from the ebsd variable.
cs=ebsd('Magnesium').CS;
m1=Miller(1,1,-2,3,cs,'UVTW') %Miller-Bravais index definition of a direction
m2=Miller(1,1,3,cs,'uvw') %Miller index definition of a direction
m3=Miller(1,1,-2,3,cs,'HKIL') %Miller-Bravais index definition of a plane
normal
m4=Miller(1,1,3,cs,'HKL') % Miller index definition of a plane normal
6+
"#1J!*
$"*+17
7$
"#
*;GGG01
%"*+L8G,8GM

1"
98F"*+
"#!#
#"
%load some test data
mtexdata twins
%copy the symmetry to a new variable
cs=ebsd('Magnesium').CS
%define the Miller indexes you want to plot
m0=Miller(1,1,-2,0,cs,'HKIL')
m1=Miller(1,1,-2,3,cs,'HKIL');
m2=Miller(1,1,-2,3,cs,'UVTW')
%create a figure
figure;plot(m0,'upper','labeled','backgroundColor','white','grid','MarkerSize'
,10)
hold on
plot(m1,'upper','labeled','backgroundColor','white','grid','MarkerSize',10)
plot(m2,'upper','labeled','backgroundColor','white','grid','MarkerSize',10)
%annotate the x and y directions
annotate(xvector,'label',{'X'},'BackgroundColor','w')
annotate(yvector,'label',{'Y'},'BackgroundColor','w')
8CCD
/6
536
($
1!
@!0%3,77?
...?
.
;6
1
($
&!
@!0%3,771
A..B

+1$
$/9

,%%
%
#1%
98D
$%K%
#!'hkl' 'uvw'#A
&$
#
%load some test data
mtexdata copper
%copy the symmetry to a new variable
cs=ebsd('C').CS
%define the Miller index you want to plot
m0=Miller(1,1,0,cs,'hkl')
m1=Miller(1,1,0,cs,'uvw')
m2=Miller(0,0,1,cs,'uvw')
%create a figure
<GCD
figure;plot(m0,'upper','labeled','backgroundColor','white','grid','Mar
kerSize',10)
hold on;
plot(m1,'upper','labeled','backgroundColor','white','grid','MarkerSize',10)
plot(m2,'upper','labeled','backgroundColor','white','grid','MarkerSize',10)
%annotate the x and y directions
annotate(xvector,'label',{'X'},'BackgroundColor','w')
annotate(yvector,'label',{'Y'},'BackgroundColor','w')
>*
$"*+!
E#!*/
"*+*#-5
''&'&27281  
(&&07
K##
1
$"*+!=#
11
*/0'
-
1
*/0'#&*/0'
#*/0'
!
>#plotPDF
16!
1,-
plotIPDF1
.%!&!!1#98C

%load the MTEX test dataset for magnesium
mtexdata twins
%load the orientations of the ebsd map into a separate variable
o= ebsd('Magnesium').orientations
%load the crystal symmetry into a variable
cs= ebsd('Magnesium').CS
%define the pole figures you want to create. Note that these indexes are
assumed to be plane normals by default
h=[Miller(0,0,0,1,cs,'hkil'),Miller(1,0,-1,0,cs,'hkil'),Miller(1,1,-
2,1,cs,'hkil'),Miller(1,1,-2,0,cs,'hkil')];
%plot the pole figure
plotPDF(o,h)
<8CD
'6 )twins
998CA8H
%
!K1
#1#
#1
figure;plotPDF(o,h)
71
I%0A8H
1GGG8
8G,8G88,<G88,<8
UP%#%
#K
;
%take the fifth point from the orientation set we defined, and move it to its
own variable
o1=o(5)
%plot just this single orientation.
figure;plotPDF(o1,h)
>#1#
%in terms of Euler angles
% zxz explicitly means Bunge convention used (this is the default).
o = orientation('euler',30*degree, 30*degree, 30*degree,'ZXZ',cs);
figure;plotPDF(o,h)
'1;!*GGG
#
%define an axes based on a sample direction
v=vector3d(xvector);
%define a rotation
omega=30*degree;
%define your orientation
ori = orientation.byAxisAngle(v,omega,cs)
<<CD
figure;plotPDF(ori,h)
)##!*/0'
%plot an ebsd map
plot(ebsd('Magnesium'),ebsd('Magnesium').orientations)
%get one point from the map
[x,y]=ginput(1);
%get the orientation based on xy coordinates.
ori1=ebsd(x,y).orientations
figure;plotPDF(ori1,h)
+
/#
#!#
#*$.?0

('''&'
'-!
-/
1##GGG8
9
*##9
&

%plot an ebsd map
plot(ebsd('Magnesium'),ebsd('Magnesium').orientations)
%select two points from the EBSD map. If you pick a point in the twin and a
point in its parent you can get the relationship between them
[x,y]=ginput(2);
%get orientations from these xy coordinates
ori1=ebsd(x(1),y(1)).orientations
ori2=ebsd(x(2),y(2)).orientations
%calculate the misorientation moving from ori2 to ori1. Note that this is an
operation where the order truly matters.
mori = inv(ori1) * ori2
%determine the axis of misorientation, rounded to integers
round(mori.axis)
%determine the misorientation in degrees
mori.angle/degree
%compare this to the angle between the (0001) axes
M=Miller(0,0,0,1,cs,'hkil');
%convert the orientations to vector3d
v1=ori1*M
v2=ori2*M
%calculate the angle between them, using the antipodal tag to use twofold
symmetry
angle(v1,v2,'antipodal')/degree
<=CD
(#>@="
51#='
/
%continuing on from the previous example, compare the misorientation that was
calculated to the angle between the (0001) axes
M=Miller(0,0,0,1,cs,'hkil');
%convert the orientations to vector3d
v1=ori1*M
v2=ori2*M
%calculate the angle between them, using the antipodal tag to use twofold
symmetry
angle(v1,v2,'antipodal')/degree
!#ori1
1"=
  
5=#:

&
1
/#="
#!
#2##
7"

%1"%1&3$C(
$
Vector3D (v) Miller (m) Orientation (o)
Vector3D v=vector3d(m) v=o*m
Miller m = Miller(v,cs)
Orientation Not possible Not possible
)!*/0'#
ebsd#%!"*+
*/0''#!#!
%>#%
#1
*/0'#H1
#F
<ACD
1$%
%!ebsd.
#1#,1

(*/0'#
#ebsd.____ 3
1
ebsd(i).____i,ebsd
*#&
6#1ebsd.id\8GG
8GGebsd ###ebsd(100)
&,
!###*/0'
&&ebsd #,
(5(.'&&(.-,
'&
*/0'$'gridify
gridifyebsd##<'
#P)
!
*/0'#
12GG$'#
&1ebsd#
-"-.-/##!
#
%separate out ebsd point with id=500
temp=ebsd(ebsd.id==500)
5##
!max(ebsd.id)maxminmean
!ebsd$
maxminmean%!
3#%
#&
1
<2CD
%1)*&ebsd&1
Variable name 6 )
ebsd.id */0'
0&8
#
"#

>

ebsd.rotations 

.&
*/0'#0
#,#
*
8<

)#
,
1
ebsd.unitCell 
scanUnit

*/0'#
1
*/0'U%
?J

*/0'
ebsd.phaseId 
8U
%.&
*/0'#
?
#
>

ebsd.phase 
GU
%.&
*/0'#*&
phaseId8
-
#
>

ebsd.mineralList 


$
phase
phaseId1
>

U$%



ebsd.bc, ebsd.bands,
ebsd.mad,ebad.bs 
E
*/0'
&6


?
,
&>

<HCD
&

ebsd.x or .y 
.
&*/0'#




6grains#&$'
#ebsd#1
#ebsd#
)'1
![grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'angle',10*degree);
ebsd.grainId 
*/0'
,

grains.id
?


ebsd('Magnesium').mis2mean "#
*/0'


?

-ebsd#&
#
,1#$
"*+1,1
#
%1/6?*ebsd
ebsd(‘Magnesium’).orientations
ebsd(‘M’).orientations
ebsd(‘m’).orientations
*

1
?*/0'
1
ebsd(‘Magnesium’).CS 




(&1




<FCD
)
6*/0'#$
ebsd.id%#8
ebsd#ebsd.x
ebsd.y#
"-.-/%!
$#*/0'
*/0'&*/0'[ebsdGrid,newId] =
gridify(ebsd) 1<'*/0'
!7,#
*/0'
)&)'
!%
%J#
#
##ebsd#
-#H#F#1
##1
#9
8G#&
ebsd#1ebsd
#U%ebsd#
#1#1
!,1,
Kebsd6!#
0
,
%load the forsterite test data.
mtexdata forsterite;
%create a logical of all forsterite ebsd points with high band contrast
log=ebsd('Fo').bc>100;
%OPTIONAL determine how many points ‘pass’ this filter
sum(log)
%OPTIONAL determine how many points ‘fail’ this filter
size(ebsd,1)-sum(log)
%Create a new variable containing only the forsterite data. If you don’t do
this, the logical and the ebsd variable will be different lengths, and the
command fails.
filteredEBSD=ebsd('f')
%create the subset by filtering the forsterite ebsd data with the logical.
filteredEBSD=filteredEBSD(log)
<DCD
%If you want to work with all phases simultaneously and not limit your result
to the forsterite data, it's even simpler
log=ebsd.bc>100;
filteredEBSD=ebsd(log)
%you can do the two above commands all in one step
filteredEBSD=ebsd(ebsd.bc>100)
6$1# ebsd #b
>
#&*/0'4J
#&#*/0'&
"*+1'
*/0'&#
#####
&
&
$$1##
*/0'
'#
plot(ebsd,ebsd.bc)
-1
#
forsteriteEBSD=ebsd('f')
*/0'
)*/0'#7

0(#&'
["
6$ ebsd #b
1
9mtexdata small
&##6
1#!b5
###
#b/#
I1
##DG#AC8C2<`
=Y5
sum(forsteriteEBSD.bc<80) ##
%load the test data
mtexdata small
<CCD
%extract the forsterite phase only
forsteriteEBSD=ebsd('f')
%get the max and min band contrast – turns out to range between 55 and 156
max(forsteriteEBSD.bc)
min(forsteriteEBSD.bc)
%plot a histogram dividing the data into four bins, using this max and min
%first, extract the band contrast values you want to plot
dataSet=forsteriteEBSD.bc
%define the histogram max and min
userMax=max(forsteriteEBSD.bc);
userMin=min(forsteriteEBSD.bc);
%divide the data into four equal bins
binNum=4;
%calculate the width the bins
width=(userMax-userMin)/(binNum);
%plot the histogram with specified bin ranges, and give it a handle.
figure;h1=histogram(dataSet,[userMin:width:userMax]);
%get information about the number of counts in each bin.
h1.BinCounts
%label your axes
xlabel('Band Contrast bin');ylabel('Counts')
%determine the number of points eliminated if you keep data with a band
contrast over 80
sum(forsteriteEBSD.bc<80)
%calculate this as a percentage of all forsterite data points
100*sum(forsteriteEBSD.bc<80)/size(forsteriteEBSD,1)
6!*/0'"
/#!*/0'
"*+
plot(ebsd('Magnesium'),ebsd('Magnesium').orientations)
1#!,
/
+5###
9<G#
9<800
9=H
=GCD
.%
%$D


6(
ipfKey =
ipfColorKey(ebsd('Magnesium').orientations)
plot(ipfKey)
5!
*/0';plot(ebsd('Magnesium'))  plot(ebsd('indexed')) 
9
twinsJ#&
,9,

/9<<
(plot(ebsd('indexed')).
7twinsforsterite
>ebsd ##
9<=

=8CD
1forsterite
3(plot(ebsd('indexed'),ebsd('indexed').bc)
*/0'
$
9<8K
0,
*/0'!#
*
0#
9<A
%load the forsterite test dataset
mtexdata forsterite
plot(ebsd('indexed'),ebsd('indexed').orientations)
 (''.,'&(
'('&&7&'
$;
%create a figure and plot the forsterite phase.
figure;plot(ebsd('f'),ebsd('f').orientations)
%cause the next two plots to display on top of the first.
hold on;
Plot the enstatite phase
plot(ebsd('e'),ebsd('e').orientations)
%plot the diopside phase
plot(ebsd('d'),ebsd('d').orientations)
hold off
$
plot(ebsd('indexed'),ebsd('indexed').orientations)!1[
twins
=<CD
 (
*/0'
>&!*/0'
1
&9D9C!*
98G!##
$*
$+,50
'-:
*(
0,
)#
('1
==CD
(
$#

*K$
*/0'#!*/0'#!
#$ebsd#
!%1
"*+,#
.*95'>6X#
9(&'1
rotate vs rotation
rotation5*#7
1
rotate#J
$%J,#7
Jrotate#D#%
!1rotation1
rotate
=ACD
/(P
*/0'4
K*#
"%
*E? $E/.
,E)/;).
)ebsd2%1;

*E? $E/.
,E357;).
9<F;ebsd3#D

*x=-70, y=-41
,E357;).
;ebsd4%1;

*x=-70, y=-41
,E)/;).
=2CD
%1;F!(
(("9$
4(<?(
(&((?
ebsd2=rotate(ebsd,90*degree,'keepXY') *()
1
,
ebsd3=rotate(ebsd,90*degree) *(/
,
1%
$$4
ebsd4=rotate(ebsd,90*degree,'keepEuler') *(;
1
,
ebsd5=flipud(ebsd) (2&$
D1,

*E? . y=24
,E(273,94,281)
ebsd6=fliplr(ebsd) (2
<$D1
,
*x=40$E/. 
,E(241,0,119)
>,,
0J
>
1*/0'#
!
>,,
51
&'
##!+5
#D0

=HCD
6$b
69==$1
!
#>$
$1
1
$9==18,=
A,2#
'1
$#D1rotate%
#1#rotate 
/1
1#E
"(9!0

1
-&.5,
crystallography&&
0'1#
?
#=$1

%define a rotation around y by 37 degrees
rot1 = rotation.byAxisAngle(yvector,37*degree)
,
-###*!#*
1*/0'#
;*/
%#"*+1%
#*
1"*+K
K*#
rot1 = rotation.byEuler(30*degree,50*degree,10*degree)
1$&
1
15=
5J#
"*+
1
=FCD

9#
0#
81##<
%define a second rotation
rot2 = rotation.byAxisAngle(yvector,48*degree)
%calculate the combination of the two rotations
rot=rot2*rot1
9,5
-$$93 '&/
#1#
J1
1#
#&

%1
'keepEuler', 'keepXY' #D

% rotate the ebsd Euler angles, and store this as a new variable
ebsd_rot = rotate(ebsd,rot,'keepXY')
#

1*/0'1#
#K5ebsd#
*#
#"-.-/
&&$"*+
$"*+#
"*+
1"*+
1+X

plotx2north
plotx2south
plotx2east
plotx2west
plotzOutOfPlane
plotzIntoPlane
=DCD
0
7*/0'c#
1;
% calculate the x span and y span
xspan=max(ebsd.x)-min(ebsd.x)
yspan=max(ebsd.y)-min(ebsd.y)
&#0
1#5
ebsd ##!1
%scale the x data down (by multiplying by a decimal), and shift it (by adding
a constant);
ebsd.x=ebsd.x*0.9108+0.0255
%P#,8
ebsd.x=-ebsd.x#-

$!#
#1#
#*
-:
-:$
$&
#
6$:b
98A982:
#
5%#

0$%0
#$%J
9:
https://people.gnome.org/~mathieu/libart/libart-affine-transformation-
matrices.html
=CCD
-:!!;
A=
(
1m1 0
m2 1 0
0 0 1
)
683
\82W\G<HF
%##-<#C0:
#
K-,
98A
-\L8G<HGIG<H8GIGG8M
Y#8<
-<\L8G<HGIG8GIGG8MY8
#<7
-=\L8GGIG<H8GIGG8M
Y<#87
-A\L8,G<HGIG8GIGG8M
Y8<
7
%1'DG
>%1:ebsd#
;
ebsdSheared = affinetrans(ebsd, A)
6:%
*9!#&
AGCD
(
017
-
&!"#
%take every 8th point, not a random sample
ebsd_tiny=ebsd(1:8:length(ebsd))
>
%take a random sample of 25% of the ebsd variable.
ebsdSub = ebsd(discretesample(length(ebsd),round(length(ebsd)*25/100)));
'1
1#"
"40&1
)' !
%#$
#*/0'&
+,#!
##

$%1
#$!
/
#&:,&;((6
9<C
61#
;111#
%##
%,
##
###9
'1#
J#9<C=G=8
;
figure; plot(ebsd); hold on; plot(grains.boundary,'linewidth',2)

figure; plot(ebsdS); hold on; plot(grains.boundary,'linewidth',2)
A8CD
'%D71H
!$1
D
% import the MTEX test dataset named ‘small’ which is a subset of the
forsterite test dataset.
mtexdata small
%if you calculated the grains at this point, and then overlaid them on
the grain boundaries, you’d get the left hand side of Figure 29. Note
that the white unindexed points have boundaries around them.
Essentially, they’re treated like their own phase.
% reconstruct the grain structure. When we do this, Let’s consider
only the indexed data, in other words, we tell MTEX that the unindexed
data is ‘empty’ inside the grains rather than another phase.
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'angle',10*degree);
A<CD
.7%,9*
H,9*(A(
1
%at this point, if we plotted the ebsd data and the boundaries, we’d
get the result shown as Figure 30 left side. Compare this to the left
side of Figure 29. The difference is that the unindexed points are no
longer treated as a separate phase.
%We’ve still got some very small grains that are only one pixel big.
Let’s remove all ebsd data belonging to grains less than three pixels
(see Figure 30 right side). Note that you’re actually deleting data
here (although the boundaries haven’t updated yet).
ebsd(grains(grains.grainSize<3)) = [];
% redo grain segmentation. Shown as Figure 31 left, the boundaries
around the grain < 3 pixels are now gone.
[grains,ebsd.grainId] = calcGrains(ebsd('indexed'),'angle',10*degree);
A=CD
9&

% smooth grain boundaries (see Figure 31, right)
grains = smooth(grains,5);
% define the filter to be used as meanFilter, and the number of
neighbours to consider
F = meanFilter;
F.numNeighbours = 3;
% smooth the data, using the filter specified. Also, fill in the
holes, keeping the grain boundaries in mind. This was shown as the
right side of Figure 29, and again as Figure 32 (left side).
ebsdS = smooth(ebsd('indexed'),F,'fill',grains);
AACD
%1$&$
('61$C
(11
5#9=<
,#,
#
&#&1
figure;plot(ebsdS('f'),ebsdS('f').orientations)
hold on
plot(ebsdS('e'),ebsdS('e').orientations)
plot(ebsdS('d'),ebsdS('d').orientations)
plot(grains.boundary,'linewidth',2)
0;
%calculate grains
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'angle',10*degree);
%remove EBSD data associated with small grains
ebsd(grains(grains.grainSize<3)) = [];
%recalculate the grains to remove boundaries around small grains.
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'angle',10*degree)
%smooth the grain boundaries (optional)
grains = smooth(grains,5);
F = meanFilter;
F.numNeighbours = 3;
%smooth and fill the ebsd data
ebsdS = smooth(ebsd('indexed'),F,'fill',grains);
A2CD
0,
!
1
%

>;#
ebsd#
%#5
#
#"#

(
#
#
ebsd_a=[ebsd_1a ebsd_2a ebsd_3a ebsd_4a]
$ JJ#8#<,
19
05
,
#
-
1*/0'
%##
###
min(ebsd.x)1#
5"
#9#ebsd
#>##

6$b
-#*/0'#
$8GG%
J15
ebsd#!5
#
##
"#
%load a test dataset
mtexdata twins
AHCD
%plot the map to work from
figure;plot(ebsd('Magnesium'),ebsd('Magnesium').orientations)
%select two coordinates representing opposite corners of a rectangle
on the active EBSD map
[x,y]=ginput(2);
%get the length of rectangle sides using the x y values from ginput.
xspan=max(x)-min(x);
yspan=max(y)-min(y);
%use these corners to define a rectangle
region = [min(x),min(y),xspan,yspan];
%create a logical of points inside the rectangle
condition = inpolygon(ebsd,region);
%Use the logical to transfer the ebsd data within the rectangle to a
new variable.
ebsdSmall= ebsd(condition);
%plot the smaller data set.
figure;
plot(ebsdSmall('Magnesium'),ebsdSmall('Magnesium').orientations);
&
hold on
rectangle('position',region,'edgecolor','r','linewidth',2);
$
/#
%if you haven’t done it already calculate the grain variable for the full data
set
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'angle',10*degree);
%Create a logical of grains data within the segmented data boundary.
[in, ~] =
inpolygon(grains.boundary.midPoint(:,1),grains.boundary.midPoint(:,2),[max(x)
min(x)], [min(y) max(y)]);
%segment the grains data to match the spatial segmentation
bound_segment=grains.boundary(in);
%plot the result
figure;plot(ebsdSmall('Magnesium'),ebsdSmall('Magnesium').orientations);
hold on
plot(bound_segment,'linewidth',2)
"#
61&
%#0#

%load some data
mtexdata twins
%plot a map if it doesn't exist
figure;plot(ebsd('Magnesium'),ebsd('Magnesium').orientations);
AFCD
%select a series of x,y points, close the shape with a right click.
poly = selectPolygon
%create a logical identifying points as inside or outside the polygon
ind = inpolygon(ebsd,poly);
% reduce the data to that within the polygon
ebsd_poly = ebsd(ind)
% show the selected polygon region
figure;plot(ebsd_poly('Magnesium'),
ebsd_poly('Magnesium').orientations);
07
#!#J!
!"0
;33#3J!3<A#A#28#AAHD#<=#2F8G
6&b
$&02+
:;.*I%*7
8Gc#8
19
==#
9=A
9=AU#%
#-
#;
#>'#9
>'9
*#
mode
=,
=7

#
=&

!!&#
#7##
#

ADCD
71(


$%*/0'
#
#%*
!b

#
#

#3
#
$

%load a magnesium test data set
mtexdata twins
%plot a map if it doesn't exist
figure;plot(ebsd('Magnesium'),ebsd('Magnesium').orientations);
%select endpoints of a line on the map and store the x and y coordinates
[x,y]=ginput(2);
ACCD
% create a variable holding the xy spatial coordinates of each end of the
desired line segment
lineSec =[x(1,:) y(1,:); x(2,:) y(2,:)];
%overlay the line you selected on the ebsd map as a visual reference
hold on;line(x,y,'linewidth',2); hold off;
%Send the line coordinates to the function spatialProfile, which will return
the EBSD data of points on the line and the distance from the first point
[ebsdLineOri,dist] = spatialProfile(ebsd('Magnesium'),lineSec);
%calculate the misorientation angle between the first point of the line (your
reference) and all the points on the line
ang= angle(ebsdLineOri(1).orientations,ebsdLineOri.orientations)./degree;
% plot this misorientation angle vs the distance along the line
figure;plot(dist,ang);
xlabel('Distance along line'); ylabel('misorientation angle in degrees')
>;

% to plot the misorientation gradient, we calculate the misorientation between
each adjacent point on the line instead. Note that we have to truncate the
variable dist by one in order to make the variable lengths match.
ebsdLineOriDelta= angle(ebsdLineOri(1:end-
1).orientations,ebsdLineOri(2:end).orientations)./degree;
hold on;
plot(dist(2:end),ebsdLineOriDelta);
hold off
%label your plot axes
xlabel('Distance along line'); ylabel('misorientation angle in degrees')
%add a legend
legend('misorientation to first point','orientation gradient')
0;"*+
-6!*/0'"1


ebsd#
#&
*/0'#$9
$#&
ebsd0
%!ebsd#
!,#
#8DFAHF
mtexdata forsterite
size(ebsd('Indexed'))
2GCD
!plot(ebsd('Indexed'),colourInfo) !
#colourInfo #88DFAHF8DFAHF8
#1$%colourInfo 
=8DFAHF#!
colourInfo(:,2))#

-*/0'
##

%load the forsterite test data
mtexdata forsterite
%create a vector array containing numbers from one to 187467
colourInfo=1:187467;
%Plot all indexed data, with an ascending colour value (from the
ascending values in the variable named colourInfo).
figure;plot(ebsd('Indexed'),colourInfo)
J
colourInfo#'
colourInfo#CGHA
0%#
+5
%calculate grains
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'angle',10*degree);
%plot the grains, coloured by the grain ID number. Note that both
parts of the variable are 3156 entries long (for the forsterite
dataset if the threshold angle was set at 10 degrees using the above
command.
figure;plot(grains,grains.id)
-0

"#09
#0-
0
!#J!
!0(<%!
%
;33#3J!3HC8<F8A=GF<8CGD<8=DDF2G=A882D
28CD
>71
$K#
7
*/0'#$9
$"-.-/parula5
!09
#*,
<'K

*/0';
%create the ipf sector/shape and color it
oM = ipfHSVKey(ebsd('Magnesium'));
%view the orientation map used
figure;plot(oM)
19<8#
#

##7&
"-.-/%*/0'
#
1=6
!%
=#0
LGGG8M=$
LGGG8M=
$1!1
#=7
%define y as the vector3d direction.
oM.inversePoleFigureDirection = yvector;
%convert the ebsd map orientations to a color based on the IPF
color = oM.orientation2color(ebsd('Magnesium').orientations);
%plot the figure using the new colour map
figure; plot(ebsd('Magnesium'),color);
-=%

oM.inversePoleFigureDirection = xvector;
color = oM.orientation2color(ebsd('Magnesium').orientations);
plot(ebsd('Magnesium'),color);
2<CD
-=##0
K1='0'
=
%define a vector3D at 45 degrees between the positive x and negative y
specimen directions
V45 = vector3d(1,-1,0);
%use this as the IPF direction
oM.inversePoleFigureDirection = V45;
%calculate the colours for each of the orientations.
color = oM.orientation2color(ebsd('Magnesium').orientations);
%plot the map using this colouration
plot(ebsd('Magnesium'),color);
$1
9
*/0'
#I#
#%
9!*3
J$7
1
#
-0;"*+##
9=A
=LGGG8M
U+%!,#
#!
7$9=A!
7
(
:;.
9=A#
07
!%"*+#
#%$
$%&
2=CD
 ,9*1$1(?
4(KL&
*&<
!9=A;
%load a magnesium sample data set
mtexdata twins
%plot the map
plot(ebsd('Magnesium'),ebsd('Magnesium').orientations)
%save the crystal symmetry info to its own variable for convenience
cs= ebsd('Magnesium').CS
>$>8;?
9=A#,*/0'
%
$

%Collect the x-y coordinates of an ebsd point by clicking on the map
[x,y]=ginput(1);
%convert the selected orientation to a vector3d representing the c axis
direction
ori1=ebsd(x,y).orientations*Miller(0,0,0,1,cs,'HKIL')
>$><;?=
%compare to one of the axis direction vectors
ori1= yvector
#8<
Iebsd
2ACD
%use the orientations of all ebsd points to calculate a vector array of
vector3D representing the c-axis directions. This will be the same length as
the ebsd variable.
ori2= ebsd('Magnesium').orientations*Miller(0,0,0,1,cs,'HKIL');
%calculate the angle between ori1 (a single vector3D) and each vector3D stored
in the variable ori2. The antipodal command means that the max allowable
value is 90 degrees rather than 180 (i.e. both ends of the c axis are
equivalent).
ang=angle(ori1, ori2,'antipodal')/degree;
%plot the map.
figure; plot(ebsd('Magnesium'),ang);
$!8#8#
!##<!
8
'#
ebsd 
*/0'#
#angZC=#
!#max(ang)
K
##

'1
"*+ebsd#
##
*/0'#9&
,((&&ebsd 
$ebsd#$'*/0'
#grains#
*/0'#$!#
"*+calcGrainsebsd
#,#!
#grains 
ebsd#
%load the magnesium test data
mtexdata twins
%define some grains, using a threshold of 10° for grain boundaries
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'angle',10*degree);
N!ebsd#grains$'&
#(#!
22CD
grains(125) 8<2grains#>
$'#?$'##
&-#
K#$'!;
temp=grains(grains.id==125
("*+##,
###

[grains,ebsd.grainId] = calcGrains(ebsd('indexed'),'threshold',
[1*degree, 10*degree]);
(#ebsd #
%grains#;
0%#ebsdgrains
#9%!

;
>8#!7;
%Find the area of the largest grain
temp1=max(grains.area)
%create a logical of grains that have their area equal to the max area
temp2=(grains.area==temp1)
%Use the logical generated to filter the grains variable.
temp3=grains(temp2)
><;
%perform all the steps above in one command
temp3=grains(grains.area==(max(grains.area)));
>=;
%#
#!
%get the maximum area of the grains, and the grain id for where it exists
[val,temp3] =max(grains.area);
%now you need to get the EBSD data. You use the grain Id (from the
grain stored in temp3) to create a logical of all ebsd points having
that grainId, then you use that as a filter on the ebsd variable.
temp4=ebsd(ebsd.grainId==temp3.id)
%plot the grain as a figure, coloured by band contrast
figure; plot(temp4,temp4.bc);
2HCD
*##,
###
#8G
##grains. grains.boundary.
#!
%1.*grains&1
grains.area c
grains.aspectRatio #

grains.boundarySize ##R8
grains.boundary #>
#
$#88
grains.centroid )
#
U%
grains.diameter #
#
grains.GOS )>0I
>
grains.grainSize #
grains.hasHole 8
grains.id $'#
grains.isBoundary (8
#
grains.meanOrientation 
grains.mineral 
grains.neighbors ,
J
grains.numNeighbors ##
grains.perimeter 
grains.phase 
grains.smooth -
grains.triplePoints 
###grains.boundary
#
/##88
%get the ID of the grain with the highest orientation spread within it.
[~,idNUM] =max(grains.GOS)
%move that grain to a separate variable
temp=grains(grains.id==idNUM)
%get information about what grains share a boundary with the selected one.
Note that this outputs a list of pairs, and the value stored in the variable
idNUM will be included on each row.
2FCD
temp.boundary.grainId
%1*1
grains.boundary.direction =%

grains.boundary.ebsdId #
!


grains.boundary.grainId $'
#
grains.boundary.length 
grains.boundary.midPoint 
#
grains.boundary.mineral 
/?#
7 #

grains.boundary.misorientation 
##
/?

grains.boundary.x or y #

0,#
#
*/0'/#!*/0'
"*+0
9=20
grains.boundary grains 
ebsd #
9=2
*/0'ebsd-
9=2##
0
7
2DCD
% plot the boundary of all
grains
plot(grains.boundary,
'linewidth',1.5)
%if you only have one phase
plot(grains,
grains.meanOrientation)
% for multiple phase plots
plot(ebsd('magnesium'),
ebsd('magnesium').orientations)
hold on
plot(grains.boundary,
'linewidth',1.5)
hist(grains) %plot the misorientation of each
point relative to the average
value
plot(ebsd('Magnesium'),ebsd('Magne
sium'). mis2mean.angle./degree);
caxis([0 5])
%plot the span of misorientations
within a grain in degrees
plot(grains,grains.GOS./degree)
"1(
!,#

2CCD
7#
"#88!
9!
#1#
% colorize grains according to area
plot(grains,grains.area)
7#
9!#

% colorize grain boundary according to misorientation angle-a good way to spot
twins
%first, get all the boundaries that are Mg on both sides (because if they
aren’t you cant calculate the misorientation across them
gB = grains.boundary('Magnesium','Magnesium')
%next use the misorientation angle to colour the plot.
plot(gB,gB.misorientation.angle)
$9
*/0'#$9#
,#,-
#%

>8;!
%create the ipf sector/shape and color it
oM = ipfHSVKey(grains);
%define the direction of the ipf
oM.inversePoleFigureDirection = xvector;
%convert the ebsd map orientations to a color based on the IPF
color = oM.orientation2color(grains.meanOrientation);
plot(grains,color)
><;!$
#
hold on#1
%create the ipf sector/shape and color it
oM = ipfHSVKey(grains('F'));
%define the direction of the ipf
oM.inversePoleFigureDirection = xvector;
%convert the ebsd map orientations to a color based on the IPF
color = oM.orientation2color(grains('F').meanOrientation);
plot(grains('F'),color)
-#grains
##ebsd #

HGCD
$,##
>##$-

%get the highest id number in the grains variable
max_id=max(grains.id)
%get the data of the grain with that id number
selGrain=grains(grains.id==max_id);
%plot that grain, and outline it.
figure;plot(selGrain,'linecolor','red','linewidth',1.5)
51
%get a logical of grains with a perimeter larger than 60 and a grain size
equal or bigger than 900
condition = grains.perimeter>60 & grains.grainSize >= 900;
%copy the grain information of these grains to a new variable
selected_grains = grains(condition)
%plot these grains
figure;plot(selected_grains,selected_grains.area)
>
%click on an existing map and get a point
[x,y]=ginput(1);
%get the grain containing these xy coordinates
selGrain=grains(x,y)
93#
?!#1

%define an orientation
o2 = orientation('euler',0*degree, 0*degree, 30*degree,'ZXZ',ebsd('f').CS);
%select grains within twenty degrees of that orientation
grains_selected = grains.findByOrientation(o2,20*degree)
1

%click on an existing map and get a point
[x,y]=ginput(1);
%get the grain
selGrain=grains(x,y)
%get all grains that are within 20 degrees of the selected grain’s orientation
grains_selected = grains.findByOrientation(selGrain.meanOrientation,20*degree)
7
!7!
.%$
"
#
%load some data
mtexdata twins
H8CD
%calculate the grains from (only) the indexed data
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'threshold',10*degree);
%to remove all grains smaller than a certain size from the calculation, create
a logical the same size as the grain list.
temp=grains.grainSize>2;
%now select the grains marked as 'true' in the logical we just created
selected_grains=grains(temp);
%check that this has worked correctly.
min(selected_grains.grainSize)
%you can calculate the mean area in um
mean(selected_grains.area)
%find out how many grains were used to calculate the mean
length(selected_grains.area)
%the map of grains used for this calculation can be seen with
figure;plot(selected_grains, selected_grains.area)
%you can now plot a histogram of the data in scan units
figure; histogram(selected_grains.area)
xlabel('grain area in scan units'), ylabel('Number of grains')
%OPTION: remove all grains that intersect the scan boundary (edge grains).
selected_INTgrains=selected_grains(selected_grains.isBoundary==0)
%the map of grains used for calculation can be seen with
figure;plot(selected_INTgrains, selected_INTgrains.area)
%you can calculate the mean area in um
mean(selected_INTgrains.area)
%find out how many grains were used to calculate the mean
length(selected_INTgrains.area)
*
.%!!
%load some data
mtexdata forsterite
%calculate grains
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'threshold',10*degree);
%Pick the grain with the largest orientation spread
[val,id] = max(grains.GOS)
grain_selected = grains(grains.id==id);
%Alternately
grain_selected=grains(grains.GOS==max(grains.GOS))
%and then plot the ebsd data for that grain only
plot(grain_selected.boundary,'linewidth',2)
hold on
plot(ebsd(grain_selected),ebsd(grain_selected).mis2mean.angle./degree)
hold off
mtexColorbar
H<CD
%or plot it colorised by orientation, with the boundary outlined
figure;plot(grain_selected.boundary,'linewidth',2)
hold on
plot(ebsd(grain_selected), ebsd(grain_selected).orientations)
hold off
71
###
%!
0
%#
K
%Create an orientation map specific to the ebsd points of the grain we
selected. This allows us to narrow the orientation map to better cover the
grain
ipfKey = ipfHSVKey(ebsd(grain_selected).CS.properGroup);
%take a look at the colour map which we’re about to customize
figure;plot(ipfKey)
%center the coloring of the IPF on the mean orientation of the grain (you’ll
get a warning here)
ipfKey.inversePoleFigureDirection =
mean(ebsd(grain_selected).orientations,'robust') * ipfKey.whiteCenter
figure;plot(ipfKey)
%shrink the range to be that of the value of the GOS (already in radians)
%since this is a 'spread' we multiply by 2, plus a bit to keep away from the
%edges of the colourmap
ipfKey.maxAngle = 2.5*max(grains.GOS);
figure;plot(ipfKey)
% plot the selected grain, with the revised orientation map with an outlined
boundary
figure;plot(grain_selected.boundary,'linewidth',2)
hold on
plot(ebsd(grain_selected),ipfKey.orientation2color(ebsd(grain_selected).orient
ations))
hold off
'1#
"$
#!#
##*
1
9"
DH<CW#^88,<G_
2HW#-KK
61
#,K1*;

H=CD
%load the twins dataset
mtexdata twins
%calculate the grains
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'threshold',10*degree);
%Copy the GB information to a new variable
gB = grains.boundary
%To not include the border of the EBSD map in calculations, create a new
variable for only the mg-mg segments
gB_MgMg = gB('Magnesium','Magnesium')
%which can then be plotted, colorised by misorientation if you want
figure;plot(gB_MgMg,gB_MgMg.misorientation.angle./degree,'linewidth',2)
mtexColorbar
cs=ebsd ('Magnesium').CS
%define an extension twin (86.29 degrees reorientation) by axis and rotation
%for magnesium extension twin
h= Miller(1,1,-2,0, cs)
twinning = orientation('axis',h,'angle',86.3*degree,cs,cs)
%for compression twin you would use the below command instead
%twinning = orientation ('axis',h,'angle',56*degree,cs,cs);
%Next we create a logical of the boundary segments within 5 degrees of the
twin relationship we just defined.
isTwinning = angle(gB_MgMg.misorientation,twinning) < 5*degree;
%locate the segments that meet this condition
twinBoundary = gB_MgMg(isTwinning)
% plot the grains, and overlay the twinning boundaries
figure;plot(grains,grains.meanOrientation)
hold on
plot(twinBoundary,'linecolor','blue','linewidth',2,'displayName','twin
boundary')
hold off
%to calculate percentages of twin boundary out of all boundary segments
100*length(twinBoundary)/length(gB_MgMg)
"#
)#
U%6
#9
!7"*+#

#
mergedGrains#
grains#
HACD
%continuing from the previous code example, let’s merge the already defined
twins with the parent grains.
[mergedGrains,parentId] = merge(grains,twinBoundary);
% plot the merged grains
figure;plot(ebsd('indexed'),ebsd('indexed').orientations)
hold on
plot(mergedGrains.boundary,'linecolor','k','linewidth',2.5,'linestyle','-',...
'displayName','merged grains')
hold off
-#
-grains#
mergedGrains#
"*+1##,
1
-
##
#-#
P##
I!#J!!
dd$(8Ddd-
##
;33#3J!3<FA8FC=G=<DGGGFACAAGHCDFG
;33#3J!3AGAHFCCCG2AG8C=H2<F282

6
9#
%Using all twinning boundary segments, get the grain ids on either side
(reduced to unique values).
twinId = unique(gB_MgMg(isTwinning).grainId);
% compute the area fraction
sum(area(grains(twinId))) / sum(area(grains)) * 100
%visualize the untwinned grains (in colour)
figure;plot(grains,grains.meanOrientation)
hold on
plot(grains(twinId))
hold off
"#
#
-*/0'#

H2CD
%get the ID of the largest grain (this function returns the value and grain
ID)
[~,bigGrainID]=max(grains.grainSize)
%get the meanOrientation
ori1=grains(grains.id==bigGrainID).meanOrientation;
%calculate a vector array of all the grain meanOrientations
ori2=grains.meanOrientation
%determine the misorientation between the grains and the reference in degrees
mori=angle(ori1, ori2)./degree;
%plot the map on a greyscale, note that the largest grain (our reference) is
black.
figure; plot(grains,mori);
colormap (gray)
setColorRange([10,70])
0
07-
U#%##
##>
0#
*#*/0'


plotAngleDistribution !
1
&!##
#
% load some data
mtexdata forsterite
%calculate grains to get misorientations to grain mean (mis2mean) added to the
ebsd variable
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'threshold',10*degree);
%copy the misorientations to grain mean for the forsterite phase
mori = ebsd('Fo').mis2mean
% plot a histogram of the misorientation angles within each grain. Note that
this is a specialized histogram function, that accepts misorientations as an
input.
figure;plotAngleDistribution(mori)
title('Misorientations to mean for forsterite grains')
%or another example.
figure;plotAngleDistribution(grains.boundary('Fo','Di').misorientation)
title('Misorientations across Forsterite-Diopside grain boundaries')
$plotAngleDistribution  !
#!
%##
HHCD
0%
!plotAngleDistribution) %
"-.-/#J#
BNDmori = grains.boundary('Fo','Fo').misorientation.angle./degree;
%since this isn’t explicitly for plotting angles, you’ll need to name the axes
manually with this method.
figure;histogram(BNDmori);
xlabel('Misorientation angles in degree')
ylabel('number of grains')
title('Misorientations across Forsterite-Forsterite grain boundaries')

$%!7J
histogramhist K
##

%plot a histogram of grain area
figure;histogram(grains.area);
xlabel('Grain area in um')
title('using the histogram command')
figure;hist(grains.area);
xlabel('Grain area in um')
title('using the hist command')
%if you input the grains parameter into the histogram functions, the default
output is a much nicer grain area percentage plot, with all axes pre-labeled.
figure;histogram(grains);
%or plotted differently
figure;hist(grains);
0#
91+5
37#
? 1 1!
7 
*I

%see if grain orientation spread is correlated to grain area.
figure; scatter(grains.GOS./degree, grains.area, 2);
xlabel('Grain orientation spread in degrees')
ylabel('Grain area in scan units')
% or we can scale the markers by the area. Since the grain size for the
forsterite dataset is large, scale the circles down by dividing by 10000.
figure; scatter(grains.GOS./degree, grains.area, grains.area/10000);
HFCD
xlabel('Grain orientation spread in degrees')
ylabel('Grain area in scan units')
%or scale the markers by the result of a calculation
figure; scatter(grains.aspectRatio, grains.area,
70*grains.area./max(grains.area));
xlabel('Grain aspect ratio')
ylabel('Grain area in scan units')
%Don’t forget you can use the spatial data for plots. One thing to watch out
for, your map may have x positive to the left. In that case, put a negative
in front of the x wherever it appears
[x, y]=centroid(grains);
figure; scatter(-x, grains.area, grains.area/10000);
xlabel('Grain centroid horizontal position');
ylabel('Size of grain in scan units');
6-
%#
$
grains.meanOrientation
#
#
#*1>*
%
1
calcDensity!>'9
#&#
&
-
9calcModes
calcModesJ
#!

U%
%load some data
mtexdata twins
%calculate the density function (see details above).
odf=calcDensity(ebsd('Magnesium').orientations,'halfwidth',10*degree);
%select the highest local maxima (mode) from the odf by using the value 1. We
only want an orientation from this function, so skip the return of the
intensity by using ~ in that place
[modes, ~] = calcModes(odf,1);
%Calculate the grains to get the grain.area and grains.meanOrientation
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'threshold',10*degree);
HDCD
%Determine the angular relationship between each grain's mean orientation and
the reference orientation
%get the orientations of the grains
ori1=grains.meanOrientation;
%calculate the misorientations on moving from ori2 to ori1
mori = inv(ori1) * modes;
%determine the angle of rotation in degrees
theta=mori.angle/degree;
%plot the data
figure; scatter(grains.area, theta, 30);
xlabel('grain area in scan units ');
ylabel('misorientation from main texture component in degrees');
.%#9
0*/0'#$9
#!
%we need to define how to convert orientations to colours, so we’ll use a
default function for that.
oM = ipfHSVKey(grains);
%convert the modal orientation into a 3D vector
dir = modes.*Miller(0,0,0,1,ebsd('Magnesium').CS);
%and use this vector as the inverse pole figure colour map direction
oM.inversePoleFigureDirection =dir;
color = oM.orientation2color(grains.meanOrientation);
scatter(grains.area, theta, 30,color,'filled');
xlabel('grain area in scan units');
ylabel('misorientation from main texture component in degrees');
-
.%
%calculate the fit parameters. The 1 here is the degree of polynomial, so in
this case, a line.
my_poly=polyfit(grains.area, theta,1);
%input a range of X values to calculate points to draw on your plot.
Grains.area runs from 0.09 to 182, so some good values for x coordinates of
your trendline might be
X= 0.1:10:180;
% use those values and the fit function to calculate matching y coordinates
Y=polyval(my_poly,X);
hold on
plot(X,Y);
hold off
0
*/0'
$$
#
[x, y]=centroid(grains);
figure; scatter(-x, grains.GOS, 30, '.');
xlabel('Grain centroid horizontal position');
ylabel('GOS in radians');
HCCD
1+<min and max(-x)
%calculate the fit parameters. integer is degree of polynomial
%(i.e. 1 for linear)
my_poly=polyfit(-x, grains.GOS,1);
% input your X data range to calculate points to plot
X2= 1:2:50;
% use those values and the fit to calculate matching y coordinates
Y2=polyval(my_poly,X2);
% plot the trendline
hold on
plot(-X2,Y2);
hold off

0#
*/0'###
#
-
b
##!##b
-K#b
'K[K%
0
#

#3;
mtexColorbar
#mtexColorMap
#
#mtexColorMap##
!
FGCD
)+%,-&$6(
(4$1(111
%to plot a map, coloured by band contrast
plot(ebsd('Magnesium'),ebsd('M').bc)
%change the color map: note this applies to active figure only
mtexColorMap magma
%you can also use matlab colormaps
colormap gray
colormap (jet)
%for inverted colormap, use
colormap(flipud(parula))
%to change the max and min values used for the colormap
setColorRange([5, 200]);
-"-.-/###
;33!33#3351
()/#
0
$"*+1
#5
;
%load the forsterite dataset
mtexdata forsterite
plot(ebsd)
%view the colour of the forsterite phase
ebsd('f').color
%change the colour
ebsd('f').color=[0.1 0.1 0.3]
%plot the map again
F8CD
plot(ebsd)
%change the colour to one of the MATLAB’s default
ebsd('f').color=str2rgb('salmon')
plot(ebsd)
$#
##
5grains#
grains('f').color=[1 0.1 0.3]$#

-#!
#text(x,y,'P').

labels=findobj(gca,'Type','Text');delete(labels);
5!#
0!
ginput
%Get some points
[x,y]=ginput(2);
%To overlay the endpoints on the map
hold on; plot(x, y, '.r', 'MarkerSize',60);hold off
>J
%To overlay a line on the map
hold on; plot(x, y, 'LineWidth',2);hold off
##3# mtexColorbar, #
"*+a!
%to hide the legend, first retrieve the name
hLeg = legend('example')
%then turn it off.
set(hLeg,'visible','off')
##5
#Jsprintf
str=sprintf('Merged ID');
set(gcf,'name',str,'NumberTitle','off');
?0
#&7
>#

9;
mtexdata titanium;ebsd.CS
=AF
mtexdata twins;ebsd.CS
F<CD
=<2<
K%##
"*+7crystalShape


4;<
('',((
O
%load some data
mtexdata twins;
%pass the crystal symmetry from the ebsd data to the crystalShape
command, and specify that this is a HCP unit cell
cS = crystalShape.hex(ebsd.CS)
%plot the crystalShape unit cell.
plot(cS)
%#
>#%*/0'
0%
%calculate the grains
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'threshold',10*degree);
%Plot a grain map, using one orientation per grain.
Figure;plot(grains,grains.meanOrientation)
hold on
9*/0'%1
.%-#
%!
$'I$'B<=
%isolate your test grain
testGrain=grains(grains.id==23);
%pick a scale to start
scale =10
%overlay the grain
plot([testGrain.centroid,scale] + testGrain.meanOrientation* cS *
scale)
9#;&#79
testGrain.centroid 
7#scale#-,7X
#
U%Jscale#
F=CD
#
&#!
scale#
7
#;scale
$scale
U#%7
&#
%once scale looks good, overlay the whole map.
%first, to simplify the command, break out the xy data.
GrainCoords=grains.centroid
%and add the z coordinates
GrainCoords(:,3)=scale
%plot the overlay
plot([GrainCoords] + grains.meanOrientation* cS * scale)
%note that if you decide to change the scale value, you must update
GrainCoords first.
scale=5
GrainCoords(:,3)=scale
figure;plot(grains,grains.meanOrientation)
hold on
plot([GrainCoords] + grains.meanOrientation* cS * scale)
/3$&$twins*"
FACD
0>"*.$"$-$>0;
$!U%#
#-
-
#
$##
#
,3$(<
9=D%
707
K
scale J
-
J7#
%continuing on from the previous example,
figure;plot(grains,grains.meanOrientation)
hold on
plot([GrainCoords] + grains.meanOrientation* cS * grains.area*0.05)
9=D;twins##
GG2;plot([GrainCoords] + grains.meanOrientation* cS *
grains.area*0.05)
F2CD
,3$$
$%19%1#7
%determine a good minimum size to use
max(grains.area)
min(grains.area)
%I’ll pick 100 as my threshold and filter the grains accordingly
threshold=grains.area>100
%use this new logical to filter your grains datasets
bigGrains=grains(threshold)
%for the twins dataset, this leaves me with 5 grains. Get the xy data
and append z values
GrainCoords=bigGrains.centroid
%and add the z data. Based on earlier plots, I know that the crystal
shapes will be scaled down by a factor of 0.05, so I need a value
larger than this.
GrainCoords(:,3)=bigGrains.area*0.1
%plot a map you can overlay
figure;plot(grains,grains.meanOrientation)
hold on
%plot the crystal shapes
plot([GrainCoords] + bigGrains.meanOrientation* cS * bigGrains.area*0.05)
,3$1$
%1#9%
small

%load a tiny segment from the forsterite dataset, and calculate grains
mtexdata small
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'threshold',10*degree);
%get the largest grain. In this line you simultaneously find the grain with
the largest area, create a logical of grains with that area (should only be
one) and then use that logical to isolate that specific grain.
refGrain=grains(grains.area==max(grains('f').area))
%Calculate the misorientation between the selected grain and all forsterite
grains in degrees
mori=angle(refGrain.meanOrientation, grains('f').meanOrientation)./ degree
%isolate the forsterite grains with a logical containing all grains within 20
degrees
fosGrains=grains('f')
SelGrains=fosGrains(mori<20)
%now we have our (in this case five) selected grains. What crystal shape
should we use for forsterite? Unfortunately, unlike hexagonal, this one isn’t
FHCD
built in. The parameters below were taken from the ‘Advanced crystal shapes’
tutorial on the website.
cs=fosGrains.CS
N = Miller({0,1,0},{0,0,1},{0,2,1},{1,1,0},{1,0,1},{1,2,0},cs)
dist = [0.4, 1.3, 1.4, 1.05, 1.85, 1.35];
cS = crystalShape( N ./ dist)
%Now we need xy coordinates for our crystal shapes
GrainCoords=SelGrains.centroid
%add a z value so they don’t clip through the map
GrainCoords(:,3)=SelGrains.area*0.1
%note that we use the truncated grain plot command below, because
plot(grains,grains.meanOrientation) would fail as this data has multiple
phases. The command below is a shortcut for this kind of data.
figure;plot(grains)
hold on
plot([GrainCoords] + SelGrains.meanOrientation* cS * SelGrains.area)
%Way too large. Scale the plot down by multiplying by a small number.
figure;plot(grains)
hold on
plot([GrainCoords] + SelGrains.meanOrientation* cS * SelGrains.area*0.001)
%much better size, but hard to see due to the same colour on the forsterite
and the phase plot.
figure;plot(grains)
hold on
plot([GrainCoords] + SelGrains.meanOrientation* cS *
SelGrains.area*0.001,'colored')
%or alternately, colour them red
figure;plot(grains)
hold on
plot([GrainCoords] + SelGrains.meanOrientation* cS *
SelGrains.area*0.001,'FaceColor','r')
%or alternately, a wireframe outline
figure;plot(grains)
hold on
plot([GrainCoords] + SelGrains.meanOrientation* cS *
SelGrains.area*0.001,'FaceColor','none','linewidth',2)
FFCD
'3$
(<
,3$(
K1
'1#
% load some data
mtexdata twins
%segment the grains
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'angle',10*degree);
% copy the symmetry to a new variable
CS = grains.CS;
%Define twins using the misorientation that will map the first miller index
onto the second, and the third miller index onto the fourth.
twinning = orientation.map(Miller(0,1,-1,-2,CS),Miller(0,-1,1,-2,CS),...
Miller(2,-1,-1,0,CS),Miller(2,-1,-1,0,CS));
% extract all Magnesium-Magnesium grain boundaries
gB = grains.boundary('Magnesium','Magnesium');
% check which of the twin boundaries are within 5 degrees of the twinning
misorientation
isTwinning = angle(gB.misorientation,twinning) < 5*degree;
twinBoundary = gB(isTwinning)
%merge grains that share a twin boundary
[mergedGrains,parentId] = merge(grains,twinBoundary);
%plot the map to select a promising area
plot(grains, grains.meanOrientation)
%click on a promising grain that has some twins adjacent and get the number
from the tooltip. I picked #84. Now find which merged grain is the parent
(i.e. merged grain containing 84)
FDCD
parentId(84)
%since mergedGrain #25 is the parent, we now want to isolate all the children
of mergedGrain #25. This will include grain 84, and several other grains that
are twins.
grainPlot=grains(parentId==25)
%Let’s plot this
figure;plot(grainPlot,grainPlot.meanOrientation)
 .+M"
&*

%1(
$&
%define the crystal shape to use
cS = crystalShape.hex(CS)
scale=10;
%define the xyz coordinates to plot at
grainPlotXYZ=grainPlot.centroid
grainPlotXYZ(:,3)=scale
%plot the crystal shapes on top of the existing figure. I had to scale the
crystal shapes down by quite a bit.
hold on;plot([grainPlotXYZ] + grainPlot.meanOrientation* cS *
grainPlot.area*.05)
,3$1,9*
$8GGG#%
,

%take every 1000th point, not a random sample)
ebsd_tiny=ebsd(1:1000:length(ebsd))
%define the crystal shape to use
cS = crystalShape.hex(CS)
scale=2
crystalXYZ=[ebsd_tiny.x,ebsd_tiny.y]
FCCD
crystalXYZ(:,3)=scale
figure;plot(ebsd, ebsd.orientations)
hold on; plot([crystalXYZ] + ebsd_tiny.orientations * cS * scale)
,3$


%plot a map if it doesn't exist
figure;plot(ebsd('Magnesium'),ebsd('Magnesium').orientations);
%select endpoints of a line on the map and store the x and y coordinates
[x,y]=ginput(2);
% create a variable holding the xy spatial coordinates of each end of the
desired line segment
lineSec =[x(1,:) y(1,:); x(2,:) y(2,:)];
%overlay the line you selected on the ebsd map as a visual reference
hold on;line(x,y,'linewidth',2); hold off;
%Send the line coordinates to the function spatialProfile, which will return
the EBSD data of points on the line as the first argument
[ebsdLineOri,~] = spatialProfile(ebsd('Magnesium'),lineSec);
%take every 20th point, so the shapes won’t overlap
ebsd_sparse=ebsdLineOri(1:20:length(ebsdLineOri))
%define the crystal shape to use
cS = crystalShape.hex(CS)
scale=2
crystalXYZ=[ebsd_sparse.x,ebsd_sparse.y]
crystalXYZ(:,3)=scale
figure;plot(ebsd, ebsd.orientations)
hold on; plot([crystalXYZ] + ebsd_sparse.orientations * cS * scale)
6!1,
*/0'#1-11

9A8
,9A8
;
%copy the crystal symmetry to a variable
cs=ebsd.CS
%define the crystal shape as an HCP unit cell
cS = crystalShape.hex(cs)
%define the orientation of the crystal shape
o = orientation('euler',30*degree, 30*degree, 30*degree,'ZXZ',cs);
%plot it at the origin
figure; plot(o * cS *0.9,'FaceColor','orange')
%add arrows to the figure along the x and y principal axes
hold on; arrow3d(0.5*[xvector,yvector],'labeled')
%you can then change the view angle using the menu in the figure window (MTEX> X axis
direction)
DGCD
9A8;-1
o = orientation('euler',30*degree, 30*degree,
30*degree,'ZXZ',cs);(;K1
6"*+#7&
1+('K
&*/0'
1plotPDF(o,h)I
1
9#
% load some data
mtexdata twins
%copy the orientation data into a variable
o=ebsd('Magnesium').orientations
%define the crystal symmetry, which you need to define Miller indexes.
cs= ebsd('Magnesium').CS
% load the desired pole figure planes into variable 'h' If the system is HCP,
these will show as miller Bravais indexes labelling the pole figures.
h=[Miller(0,0,1,cs), Miller(1,0,0,cs),Miller(1,1,1,cs),Miller(1,1,0,cs)];
%Plot the pole figures.
plotPDF(o,h);
-'"
1##!
#!0
19A<4$.",
/#
&#!LM
D8CD
9A<;-1##
>1
#$#1&
#K

h=[Miller(0,0,0,1,cs,'UVTW'), Miller(1,0,-1,0,cs,'UVTW'),Miller(1,1,-
2,1,cs,'UVTW'),Miller(1,1,-2,0,cs,'UVTW')];
1%

?1"*+
*/0'$7#
61=
-GGG8
8G,8G
9A<7#K
K1#
'MarkerSize'.
?9
9A<a<<!#A8H
1#'points','all'  'points',5000
1#(#&&
##&!
-#1
%copy your orientations for plotting
o=ebsd('Magnesium').orientations
%copy your crystal symmetry info
cs= ebsd('Magnesium').CS
%define your planes to plot
D<CD
h=[Miller(0,0,0,1,cs,'HKIL'), Miller(1,0,-1,0,cs,'HKIL'),Miller(1,1,-
2,1,cs,'HKIL'),Miller(1,1,-2,0,cs,'HKIL')];
figure;plotPDF(o,h,'points','all', 'MarkerSize',1);
1#
#
"1
5%1
1
# K
1!#;1
$
K
*%P
1"*+
6
%load some data
mtexdata twins
%copy the crystal symmetry to a new variable
cs=ebsd('Magnesium').CS
%define some pole figures to plot
h=[Miller(0,0,0,1,cs,'HKIL'), Miller(1,0,-1,0,cs,'HKIL')];
%Define the classic cube texture for magnesium
CubeMg = orientation.cube(cs)
%overlay these two on a pole figure (which we can do because they have the
exact same symmetry
figure;plotPDF(CubeMg,h,'all','grid');
hold on
plotPDF(ebsd('m').orientations,h,'all','grid');
0J;&
1P<'
P#
%%!
#9A=
K2W
&3eangle
#&earea
0eangle1%
!
figure;plotPDF(o,h,'points','all','projection','eangle','MarkerSize',1);
D=CD
9A=;J*&
J'eangle' $*&
J 'earea'  'Schmidt'"*+
J;
5%!0$7
!U%*/0'$
%enter an Euler orientation
o = orientation('euler',30*degree, 30*degree, 30*degree,'ZXZ',cs);
h=[Miller(0,0,0,1,cs,'HKIL'), Miller(1,0,-1,0,cs,'HKIL'),Miller(1,1,-
2,1,cs,'HKIL'),Miller(1,1,-2,0,cs,'HKIL')];
% the plot command for all points, upper hemisphere, stereoscopic projection
plotPDF(o,h,'points','all','upper','projection','eangle','MarkerSize',1);
 ,DN%upper
9lower
DACD
);KGD#!
-9A=
%'grid'=adds a spherical grid
%' grid_res '= (optional argument for the grid function) sets resolution in
degrees
'grid','grid_res',15*degree,
figure;plotPDF(o,h,'points','all','upper','projection','eangle',
'grid','grid_res',15*degree,'MarkerSize',1);
()/LGDGDGDM#
#open sphericalPlot
<DC=G=
LDDDM1%%
"#
I#
61()/G88A8DC
GYA2Y/FAY#1#
"1
"11
U%
%copy the ebsd magnesium orientations to a new variable.
o=ebsd('Magnesium').orientations
%copy the crystallographic symmetry
cs= ebsd('Magnesium').CS
%select some crystallographic planes to plot.
h=[Miller(0,0,1,cs), Miller(1,0,0,cs)];
%Choose a nice dark green
mb = @() [0.1, 0.5, 0.4];
%plot the figure with stereoscopic projection.
plotPDF(o,h,'upper','projection','eangle','points','all','MarkerColor',mb(),
'MarkerSize',1);
79#,#
##00;
"*+N#color
###o

%copy the ebsd magnesium orientations to a new variable.
o=ebsd('Magnesium').orientations
%copy the crystallographic symmetry
cs= ebsd('Magnesium').CS
%select some crystallographic planes to plot.
h=[Miller(0,0,1,cs), Miller(1,0,0,cs)];
color= ebsd('Magnesium').bc;
D2CD
figure; plotPDF(o,h,'upper','projection','eangle','points','all',
'property',color, 'MarkerSize',1);
$%ocolour#
#
#
figure; plotPDF(o,h,'upper','projection','eangle','points',200, 'property',color,
'MarkerSize',3);
79#,$9
%#
1
%generate the orientation map, converting orientation to colour
oM = ipfHSVKey(ebsd('Magnesium'))
%define the direction of the ipf coloration to use
oM.inversePoleFigureDirection = yvector;
%use the oM to convert the ebsd map orientations to a color based
color = oM.orientation2color(ebsd ('Magnesium').orientations);
figure; plotPDF(o,h,'upper','projection','eangle','points','all',
'MarkerSize',1,'property',color)
07
9#!75
'MarkerSize' #9
97
-
1#1
$"*+
#
%to remove all existing text on a figure, including the PF orientation
w = findall(gcf,'type','text');
set(w,'visible','off')
%to label the axes, the following inserts a square marker and a label. The
square brackets are the vector 3D to label, the content in curly braces is the
text to put at the positions in the square brackets, and at the end is the
background colour of the text label.
annotate([xvector, yvector, zvector], 'label', {'x','y', 'z'},
'BackgroundColor', 'w');
% the following inserts a label at the selected point with no marker – note
that the text is offset due to the invisible marker
annotate(zvector,'Marker','none','label',{'R'},'BackgroundColor','w')
%for more control of the marker, the standard matlab options apply
annotate(zvector,'Marker','o','MarkerFaceColor','red','label',
{'R'},'BackgroundColor','w','VerticalAlignment','top')
DHCD
You can also use the text command, which has no marker and positions your
label centered at the designated location.
text(xvector,'add2all','G')
#@='
119

#='
1
V3=vector3d(1,1,0)
circle(V3,10*degree,'add2all')
'9,1
11
0!*
1$  #
-
19A89AA-##
>*#*

%the zxz explicitly means Bunge convention used (this is the default).
o = orientation('euler',30*degree, 30*degree, 30 *degree,'ZXZ',cs);
figure; plotPDF(o,h,'upper','projection','eangle', 'MarkerSize',5)
"1
.%#
1
%plot the ebsd map
plot(ebsd('Magnesium'), ebsd('Magnesium').orientations)
%get the x y coordinates of the points
[x,y]=ginput(2);
% load the first orientation into a variable
o1=ebsd(x(1),y(1)).orientations
% load the second origination into a variable
o2=ebsd(x(2),y(2)).orientations
%Finally, plot the pole figures
h=[Miller(0,0,0,1,cs,'HKIL'), Miller(1,0,-1,0,cs,'HKIL'),Miller(1,1,-
2,0,cs,'HKIL')];
figure;plotPDF(o1,h,'upper','grid','grid_res',15*degree,'projection','eangle',
'MarkerSize',10,'DisplayName','orientation 1')
hold on
plotPDF(o2,h,'upper','grid','grid_res',15*degree,'projection','eangle',
'MarkerSize',10, 'DisplayName','orientation 2')
%now add a legend
legend show
DFCD
1
5$%
S*71
"!!T(#uvtw
hkiluvw "
#1#0#A

%first define the crystal symmetry;
cs= ebsd('Magnesium').CS
%then define two directions to plot
m_dir = Miller(1,1,-2,3,cs,'UVTW')
m2_dir = Miller(1,1,-2,0,cs,'UVTW')
%plot one direction, hold the figure, and add the other.
figure;plot(m_dir,'upper','labeled')
hold on
plot(m2_dir,'upper','labeled')
%Define and plot the plane normal. Note that the plane normal is not equal to
the direction for HCP systems, and note the different brackets used to
indicate this on the pole figure.
m_plane = Miller(1,1,-2,3,cs,'hkil')
plot(m_plane,'upper','labeled')
%Plot the trace of the lattice plane corresponding to the Miller index we just
plotted
plot(m_plane,'plane','linecolor','r','linewidth',2)
%Because this plot axes align with the unit cell, we can draw that on as well,
showing how MTEX orients things by default.
cShape=crystalShape.hex(cs)
%plot the shape
plot(cShape,'figSize','small')
1
$
>%meanOrientation#
grains###
%start with some single phase ebsd data
mtexdata twins
%calculate the grains (assuming magnesium data)
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'angle',10*degree);
%duplicate the crystal symmetry to a new variable
cs= ebsd('Magnesium').CS
%Select some planes for the pole figure
h=[Miller(0,0,0,1,cs,'HKIL'), Miller(1,0,-1,0,cs,'HKIL'),Miller(1,1,-
2,1,cs,'HKIL'),Miller(1,1,-2,0,cs,'HKIL')];
%plot the pole figure of mean orientations, including all points.
figure;
plotPDF(grains('Magnesium').meanOrientation,h,'upper','projection','eangle','p
oints','all', 'MarkerSize',4);
%title the figure
DDCD
set(gcf,'name','Grain mean orientations','NumberTitle','off');
9*/0'#
$#1&#

#*/0'&&
!%#!
>$
9mtexdata twins"-'8C7#
#&3&#
%filter on MAD lower or equal to 1, by first creating a logical of passing
data
temp=ebsd.mad<=1;
%then load the conforming data into a new matrix
ebsdFiltered=ebsd(temp);
cs=ebsd.CS;
%Optional: check it worked, the line below should give values < or = 1
%max(ebsdFiltered.mad)
%select which pole figures to plot
h=[Miller(0,0,0,1,cs,'HKIL'), Miller(1,0,-1,0,cs,'HKIL')];
%plot about half of the data.
figure;plotPDF(ebsdFiltered('Magnesium').orientations,h,'upper','projection','
eangle','points',10000, 'MarkerSize',1)
% optional: determine what percentage of points passed the filter
100*size(ebsdFiltered,1)/size(ebsd,1)
<
.D%
#
%create a logical
temp=grains.grainSize>=8;
%filter with the logical
grainsFiltered=grains(temp);
%optional: check the result
min(grainsFiltered.grainSize)
%select which pole figures to plot
h=[Miller(0,0,0,1,cs,'HKIL'), Miller(1,0,-1,0,cs,'HKIL')];
figure;plotPDF(grainsFiltered
.meanOrientation,h,'upper','projection','eangle','points','all',
'MarkerSize',5)
%now scale the points with the grain size.
figure;plotPDF(grainsFiltered
.meanOrientation,h,'upper','projection','eangle','points','all',
'MarkerSize',grainsFiltered.grainSize)
%too big, scale them down
DCCD
figure;plotPDF(grainsFiltered
.meanOrientation,h,'upper','projection','eangle','points','all',
'MarkerSize',0.5*grainsFiltered.grainSize)
%add some colour, since grain size is scalar we can use it directly
figure;plotPDF(grainsFiltered
.meanOrientation,h,'upper','projection','eangle','points','all','property',gra
insFiltered.grainSize, 'MarkerSize',0.5*grainsFiltered.grainSize)
%change the colour map of the active pole figure
mtexColorMap magma
9A2;1twins#
7
1
!

#+('
#"
J6!
1,>!
MarkerSize%
1>'9
#&1
!+5
>'91!
1
!9
AH9>'9%1
!%
0b6"*+
!$,9*0*/0'
CGCD
!b!

-U%$
S##
T>S>'9UP%T
8 < =
2 8G



 )*(#
D!($

01#
9AF1
1>'9
%load some data
mtexdata copper
%copy the copper crystal symmetry to a separate variable
cs=ebsd('Co').CS
%calculate the grains to get one orientation per grain
C8CD
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'angle',10*degree);
%calculate the kernel/halfwidth to use
psi = calcKernel(grains('co').meanOrientation)
%calculate the ODF
odf = calcDensity(ebsd('co').orientations,'kernel',psi)
%alternatively, define the halfwidth manually
%odf = calcDensity(ebsd('co').orientations,'halfwidth',5*degree)
%designate the cubic plane to use for the pole figure
h=[Miller(0,0,1,cs)];
%the ODF can then be plotted on pole figure.
figure; plotPDF(odf,h,'upper','projection','eangle');
>
#
1U%
'contour'1'contourf'9AF
%Default colouration
plotPDF(odf,h,'upper',
'projection','eangle');
plotPDF(odf,h,'upper','pr
ojection','eangle','conto
ur')
plotPDF(odf,h,'upper',
'projection','eangle',
'contourf')
 /%small#($

61#
%9!

KI%
>'9
'minmax'
'contour',0.5:8 or 'contourf', 0.5:3:8 
1##

C<CD
%plot the ODF with filled contours.
plotPDF(odf,h,'upper', 'projection','eangle', 'contourf',0.5:3:8,'minmax')
*1
*calcModes
*/0'
'1'&'( (5&#1
%11%
%
/example11
calcPDF!#
>'9
#0#-
1='#

>('&&'calcPDF''
?,&(&.%
#11
9AD
%load some data
mtexdata copper
%copy the symmetry data to a new variable
cs=ebsd('c').CS;
%calculate the grains (used for halfwidth calculation)
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'angle',10*degree);
%calculate the optimum halfwidth
psi = calcKernel(grains('c').meanOrientation)
%calculate the ODF
odf = calcDensity(ebsd('c').orientations,'kernel',psi)
%define the first pole figure and plot it
h=[Miller(0,0,1,cs)];
figure;plotPDF(odf,h,'antipodal','projection','eangle','contourf','minmax');
%get the maximum intensity on this pole figure
pdf=calcPDF(odf,h)
[~,pos]=max(pdf)
%annotate it
annotate(pos, 'MarkerSize',10,'label','max')
%note that if the annotation does not appear, you may have to switch
upper/lower on the pole figure plot
%repeat for two more pole figures
h=Miller(1,1,1,cs);
h=Miller(1,1,0,cs);
.!9ADK
1$( '
C=CD
&,(5&-
1
 ;3?
($4
9AC9AD
%define the pole figures
h=[Miller(0,0,1,cs),Miller(1,1,1,cs),Miller(1,1,0,cs)];
%plot the pole figures
figure;plotPDF(odf,h,'antipodal','projection','eangle','contourf','minmax');
%calculate the highest intensity mode
[modes, ~] = calcModes(odf,1);
%annotate them on the figure
annotate(modes, 'MarkerSize',10,'label','mode')
99AC
1#!
-!GG8
88888G%#
PK1
 '3(1
CACD
?">'9
0>'9%&
K
>'9#'&5(
&&3+&
"calcModes
!>'9#1
!0[modes, int] =
calcModes(odf,3)#
$#1$
U%$%#
[modes, ~] = calcModes(odf,3)).
#
#*/0'
92G
%load some data
mtexdata copper
%copy the copper crystal symmetry to a separate variable
cs=ebsd('Co').CS
%calculate the grains to get one orientation per grain
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'angle',10*degree);
%calculate the kernel/halfwidth to use
psi = calcKernel(grains('co').meanOrientation)
%calculate the ODF so we can calculate the mode
odf = calcDensity(ebsd('co').orientations,'kernel',psi)
%select the greatest intensity maxima from the odf as an orientation in the
variable 'modes', and skip return of the intensity by using ~ in that place
[modes, ~] = calcModes(odf,1);
%since we’re working with angles rather than misorientations, convert to
vector3d
dir = modes.*Miller(0,0,1,cs);
%likewise convert all the ebsd orientations to vector3d
delta= ebsd('Co').orientations*Miller(0,0,1,cs);
%calculate the angles between the two, taking the minimum value in either
hemisphere
ang=angle(dir, delta,'antipodal')/degree;
%and plot a histogram
figure;histogram(ang);
xlabel('angle to mode in degrees')
ylabel('count')
C2CD
Figure 50: Angle between all data points and the mode
'#=',

#%
#
(#
(!>'9

%load some data
mtexdata twins
%copy the symmetry to a new variable
cs=ebsd ('Magnesium').CS
%calculate grains (required to determine the optimum halfwidth to use)
[grains,ebsd.grainId,ebsd.mis2mean] =
calcGrains(ebsd('indexed'),'angle',10*degree);
%calculate the kernel/halfwidth to use for ODF calculation
psi = calcKernel(grains('M').meanOrientation)
%calculate the ODF so we can calculate the mode
odf = calcDensity(ebsd('M').orientations,'kernel',psi)
%select the peak orientation from the odf, and input into a separate variable
[modes, ~] = calcModes(odf,1);
>8;='!
%convert the mode orientation into a 3D vector representing the c axis
dir = modes.*Miller(0,0,0,1,cs);
%convert all EBSD orientations to 3D vectors representing the c axis
cdir=ebsd('Magnesium').orientations.*Miller(0,0,0,1,cs);
%set a threshold for your area fraction calculation
inAng=angle(cdir,dir,'antipodal')< 30*degree;
%calculate the area fraction in degrees
frac=sum(inAng)/length(ebsd('Magnesium'))*100
0#2GY=GW
U%
&
><;-!
%calculate the misorientation between the mode and all other orientations in
degrees
CHCD
m1= angle(modes(1), ebsd('Magnesium').orientations,'antipodal')/degree;
%calculate a logical of orientations being within 30 degrees of the mode in
degree units
inOri=m1<30;
frac1=sum(inOri)/length(ebsd('Magnesium'))*100
0#<DY*/0'=GW$
!#8KU%
<

>*/0'#>'9
#
,19
5
&6!#
*/0'[>'9
5,1#"*+%
##5
JoriREF *1
'
#=',
%Define the cube texture (an orientation) as a reference
oriREF = orientation.cube(cs)
%compare to the odf. Multiplying by 100 gives us the result as a percentage
v = 100*volume(odf,oriREF,10*degree)
#!

.%!#
%overlay these two on a pole figure (which we can do because they have the
exact same symmetry
figure;plotPDF(odf,h,'antipodal','projection','eangle','contourf','minmax');
hold on;plotPDF(oriREF,h,'all','grid','markercolor','r');
%annotate the cube textures
annotate(oriREF, 'MarkerSize',10,'label','Cube')
#
#
0!I
8 $*/0'!
$ebsd('magnesium')
ebsd
< "*+I
ebsd.orientationsgrains.meanOrientation
= -grains.neighbors
CFCD
A $!!"*+# https://github.com/mtex-
toolbox/mtex/discussions
2 9;33#3B0
)
$#!*/0'7
,
#"*+#1
##+51#
1
"F<


"&(

CDCD
ResearchGate has not been able to resolve any citations for this publication.
ResearchGate has not been able to resolve any references for this publication.