{plot (ebsd)
ebsd('Magnesium')
ebsd('Magnesium').orientations
plot(ebsd('Magnesium'),ebsd('Magnesium').orientations,'micronbar','off')
% reconstruct grains with theshold angle 10 degree
grains = calcGrains(ebsd('indexed'),'theshold',10*degree)
% smooth the grains to avoid the stair casing effect
grains = smooth(grains,5);
% plot the grain boundaries on top of the ipf map
hold on
plot(grains.boundary,'lineWidth',1.5)
hold off
%Once the data is in grains, extract the GB information
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',1.5)
mtexColorbar
histogram(gB_MgMg.misorientation.angle./degree,40)
xlabel('misorientation angle (degree)')}