### cprintf Initialization File Syntax Example (MATLAB) Source: https://github.com/mtex-toolbox/mtex/blob/develop/tools/misc_tools/cpini.txt This snippet demonstrates the syntax for defining options and their values in a cprintf initialization file. It includes examples of different data types like numbers, cells, and anonymous functions, as well as comments. This file format is specific to the mtex-toolbox. ```MATLAB ,, , ; note nonsense options FOO_xx decoding starts after FIRST occurrence of a typical option pair: '-begin','start of options'; % an option comment '-FOO_x1',{ 1 2 3 % a cell comment 3 2 1 }; % a line comment '-mt',1,'-nd',pi '-Lcs','=', '-Lr' , , , , , ,num2cell(--5:-10*-1); ,,,'-Lc' , ,{'X','Y'}.' '-FOO_x2',{{'abc',1,'12'},'foo',--12:--23} '-FOO_x3',rand(2,2,3) '-FOO_x4',,,,'-FOO_x5','-E',@(x) sprintf('%s',class(x));;'-t','+';,;,,; '-FOO_x6'= { 1 2 3 3 2 1 };'-FOO_x7',{1,2,3;4,5,6};,,'-FOO_x8','-',;; '-tab',10,,,'-f','-',,,,, '-FOO_x8','foo' ; ,; ``` -------------------------------- ### Initialize MTEX in MATLAB Source: https://context7.com/mtex-toolbox/mtex/llms.txt This snippet demonstrates how to initialize the MTEX toolbox within a MATLAB session by navigating to the installation directory and running the startup script. It also shows how to check the installed version. ```matlab % Navigate to MTEX installation directory cd /path/to/mtex % Initialize MTEX startup_mtex % MTEX initializes with version information and sets up paths % Output: initialize mtex-6.1.0 ...... % Check installation getMTEXpref('version') ``` -------------------------------- ### Get Supported Palette Names Source: https://github.com/mtex-toolbox/mtex/blob/develop/extern/colornames/html/colornames_doc.html Returns a cell array of all supported color palette names. This function is called with no input arguments and one output argument to retrieve the list of available palettes. ```matlab palettes = colornames() palettes = 'Alphabet' 'AmstradCPC' 'AppleII' 'Bang' 'BS381C' 'CGA' 'Crayola' 'CSS' 'dvips' 'Foster' 'HTML4' 'ISCC' 'Kelly' 'MacBeth' 'MATLAB' 'Natural' 'R' 'RAL' 'Resene' 'Resistor' 'SherwinWilliams' 'SVG' 'Tableau' 'Thesaurus' 'Trubetskoy' 'Wikipedia' 'Wolfram' 'X11' 'xcolor' 'xkcd' ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Get Color Names and RGB Values for a Palette Source: https://github.com/mtex-toolbox/mtex/blob/develop/extern/colornames/html/colornames_doc.html Retrieves all color names and their corresponding RGB values for a specified palette. The function is called with the palette name as input, returning two output arguments: color names and RGB values. ```matlab \[clr,rgb\] = colornames('MATLAB') clr = 'Black' 'Blue' 'Cyan' 'Green' 'Magenta' 'Red' 'White' 'Yellow' rgb = 0 0 0 0 0 1 0 1 1 0 1 0 1 0 1 1 0 0 1 1 1 1 1 0 ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Match Color by Index, Name, or Both Source: https://github.com/mtex-toolbox/mtex/blob/develop/extern/colornames/html/colornames_doc.html Demonstrates matching colors in palettes that use leading index numbers. Matches can be made using just the index number, just the name, or a combination of both. ```matlab colornames('CGA','9','LightBlue','9LightBlue') ans = '9 Light Blue' '9 Light Blue' '9 Light Blue' ``` -------------------------------- ### Match Color by Initial Letter Source: https://github.com/mtex-toolbox/mtex/blob/develop/extern/colornames/html/colornames_doc.html Illustrates how palettes like 'Alphabet', 'MATLAB', and 'Natural' support matching colors by their initial letter. A special case exists for 'Black', which is matched by 'k'. ```matlab colornames('MATLAB','c','m','y','k') ans = 'Cyan' 'Magenta' 'Yellow' 'Black' ``` -------------------------------- ### List Supported Palettes in MATLAB Source: https://github.com/mtex-toolbox/mtex/blob/develop/extern/colornames/html/colornames_doc.html Call the COLORNAMES function without input or output arguments to display a list of all supported color palettes in the MATLAB command window. This helps in understanding the available options for color matching. ```matlab colornames() ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Compile NFFT with Custom Configuration Source: https://github.com/mtex-toolbox/mtex/blob/develop/extern/nfft_openMP/readme.md This bash script compiles the NFFT library with support for nfsoft, nfsft, OpenMP, and portable binaries, specifying the MATLAB directory. Ensure you have the necessary build tools and the FFTW library installed before running. ```bash ./bootstrap.sh ./configure --with-matlab=MATLAB_DIR --enable-nfsoft --enable-nfsft --enable-openmp --enable-portable-binary make ``` -------------------------------- ### Untitled No description -------------------------------- ### Handle Unmatched Color Names Error (MATLAB) Source: https://github.com/mtex-toolbox/mtex/blob/develop/extern/colornames/html/colornames_doc.html This snippet demonstrates the error handling when `colornames` cannot match input color names to a specified palette. It shows the error message, lists similar color names found, and provides advice on how to list all available color names or visualize the palette. ```matlab colornames('CSS', 'bleu', 'blanc', 'rouge') ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Match RGB to Closest Palette Color Source: https://github.com/mtex-toolbox/mtex/blob/develop/extern/colornames/html/colornames_doc.html Matches input RGB triples to the closest RGB triples available in the specified palette. The function returns the color name and the matched RGB value. ```matlab \[clr,rgb\] = colornames('HTML4', [0,0.2,1;1,0.2,0]) clr = 'Blue' 'Red' rgb = 0 0 1 1 0 0 ``` -------------------------------- ### Match Color Names within a Palette Source: https://github.com/mtex-toolbox/mtex/blob/develop/extern/colornames/html/colornames_doc.html Matches input color names to the closest color names within a specified palette. The function handles flexible matching, ignoring case and spaces in many cases. Input names can be provided in a cell array or as separate arguments. ```matlab \[clr,rgb\] = colornames('xkcd',{'red','green','blue'}) clr = 'Red' 'Green' 'Blue' rgb = 0.89804 0 0 0.082353 0.6902 0.10196 0.011765 0.26275 0.87451 ``` ```matlab \[clr,rgb\] = colornames('xkcd','eggshell','eggShell') clr = 'Eggshell' 'Egg Shell' rgb = 1 1 0.83137 1 0.98824 0.76863 ``` -------------------------------- ### Visualize Palette Colors in 3D (MATLAB) Source: https://github.com/mtex-toolbox/mtex/blob/develop/extern/colornames/html/colornames_doc.html The `colornames_cube` function visualizes color palettes in a 3D color cube. The data cursor can be used to view color names by clicking on nodes. Users can select the palette and the color space for the cube. This function requires a palette name and a color space specification (e.g., 'Lab'). ```matlab colornames_cube('CSS','Lab') ``` -------------------------------- ### Calculate DeltaE for Color Palette Matching (MATLAB) Source: https://github.com/mtex-toolbox/mtex/blob/develop/extern/colornames/html/colornames_doc.html The `colornames_deltaE` function calculates deltaE metrics to match input RGB colormaps to specified palette colors. It takes a palette name and an Nx3 colormap as input, and outputs a list of deltaE metrics with the matched colors displayed. Dependencies include the `jet` function for generating sample colormaps. ```matlab colornames_deltaE('HTML4',jet(16)) ``` -------------------------------- ### Visualize Palette Colors in 2D (MATLAB) Source: https://github.com/mtex-toolbox/mtex/blob/develop/extern/colornames/html/colornames_doc.html The `colornames_view` function visualizes color palettes in a 2D plot. Users can select the palette and sorting method via drop-down menus. Clicking on a color displays its approximate hex RGB value. The function requires a palette name and a sorting option (e.g., 'Lab'). ```matlab colornames_view('dvips','Lab') ``` -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Untitled No description -------------------------------- ### Import and Visualize EBSD Data in MATLAB Source: https://context7.com/mtex-toolbox/mtex/llms.txt This snippet demonstrates how to load EBSD measurement data from various file formats (e.g., .ctf, .ang) using the EBSD.load function in MTEX. It also shows how to access and visualize different properties of the EBSD data, such as orientations, spatial coordinates, phases, and quality metrics like band contrast and mean angular deviation. Subsetting data by phase or spatial region is also covered. ```matlab % Import EBSD data (automatically detects format) ebsd = EBSD.load('mydata.ctf') % Supported formats: .ang, .ctf, .osc, .hdf5, .h5, .dream3d % Import with specific interface (optional) ebsd = EBSD.load('mydata.ang', 'interface', 'ang') % View data structure ebsd % Output shows: number of points, phases, properties, grid type % Access properties ebsd.orientations % Orientation data ebsd.x, ebsd.y % Spatial coordinates ebsd.phaseId % Phase identification ebsd.prop.bc % Band contrast (quality metric) ebsd.prop.mad % Mean angular deviation % Select specific phase ebsd_iron = ebsd('Iron') ebsd_indexed = ebsd('indexed') % Only indexed points ebsd_notindexed = ebsd('notIndexed') % Spatial subsetting region = [0 0 100 100]; % [xmin ymin xmax ymax] ebsd_region = ebsd(inpolygon(ebsd, region)) % Plot phase map figure plot(ebsd) % Displays color-coded phase map % Plot orientation map (IPF coloring) figure plot(ebsd('Iron'), ebsd('Iron').orientations) colorbar % Plot property map figure plot(ebsd, ebsd.prop.bc) colorbar mtexColorMap black2white ``` -------------------------------- ### Match RGB with Custom Color Difference Metric Source: https://github.com/mtex-toolbox/mtex/blob/develop/extern/colornames/html/colornames_doc.html Matches input RGB values to the closest palette colors using a specified color difference metric. The default is 'CIE94', but others like 'CIEDE2000', 'CIE76', 'DIN99', 'CMCl:c', and 'RGB' can be selected. ```matlab rgb = [0,0.5,1]; colornames('HTML4',rgb,'CIEDE2000') ans = 'Gray' ``` ```matlab rgb = [0,0.5,1]; colornames('HTML4',rgb,'CIE94') % default. ans = 'Blue' ``` ```matlab rgb = [0,0.5,1]; colornames('HTML4',rgb,'CIE76') % i.e. CIELAB. ans = 'Navy' ``` ```matlab rgb = [0,0.5,1]; colornames('HTML4',rgb,'DIN99') % better than CIELAB. ans = 'Gray' ``` ```matlab rgb = [0,0.5,1]; colornames('HTML4',rgb,'CMCl:c') ans = 'Fuchsia' ``` ```matlab rgb = [0,0.5,1]; colornames('HTML4',rgb,'RGB') ans = 'Teal' ``` -------------------------------- ### Untitled No description -------------------------------- ### Accessing Algorithm Status Information (MATLAB) Source: https://github.com/mtex-toolbox/mtex/blob/develop/extern/maxdistcolor/html/maxdistcolor_doc.html This snippet shows how to retrieve detailed status information from the maxdistcolor algorithm. By returning the third output argument, a structure containing metrics like minimum distances, execution time, and iteration count can be obtained. This is useful for understanding the performance and results of the color maximization process. ```MATLAB [~,~,status] = maxdistcolor(N,fun) ``` -------------------------------- ### Specify RGB Bit Depth for Color Generation Source: https://github.com/mtex-toolbox/mtex/blob/develop/extern/maxdistcolor/html/maxdistcolor_doc.html Generates colors by specifying the bit depth for Red, Green, and Blue channels using 'bitR', 'bitG', and 'bitB' options. This allows for control over the size of the RGB gamut, affecting color choice and performance. Example shows generation with 2 bits per channel. ```matlab clf('reset') rgb = maxdistcolor(64,@sRGB_to_CIELab, 'bitR',2,'bitG',2,'bitB',2, 'exc',[]); scatter3(rgb(:,3),rgb(:,2),rgb(:,1), 256, rgb, 'filled') grid('on') view(40,32) ``` -------------------------------- ### Work with Miller Indices in MTEX Source: https://context7.com/mtex-toolbox/mtex/llms.txt This code segment demonstrates how to use Miller indices for crystallographic directions and planes within the MTEX toolbox. It includes examples for creating plane and direction indices, handling hexagonal systems with 4-index notation, calculating symmetrically equivalent variants, and finding the angle between planes/directions. ```matlab % Define crystal symmetry cs = crystalSymmetry('m-3m', [2.9, 2.9, 2.9], 'mineral', 'Copper') % Create Miller indices for planes (hkl) h_planes = Miller(1, 1, 1, cs) % {111} family h_slip = Miller(1, 1, 0, cs, 'hkl') % {110} planes % Create Miller indices for directions (uvw) d_directions = Miller(1, 0, 0, cs, 'uvw') % <100> directions % Hexagonal systems use 4-index notation (hkil) cs_hex = crystalSymmetry('6/mmm', [3.2, 3.2, 5.1]) h_hex = Miller(1, 0, -1, 0, cs_hex) % {10-10} prism planes % Calculate all symmetrically equivalent variants h_111 = Miller(1, 1, 1, cs) h_all = h_111.symmetrise % Returns: all {111} planes considering crystal symmetry % Angle between planes/directions angle(Miller(1,1,1,cs), Miller(1,0,0,cs)) / degree % Returns: 54.74 degrees ``` -------------------------------- ### Visualize Sort Path: Closed vs. Open Source: https://github.com/mtex-toolbox/mtex/blob/develop/extern/maxdistcolor/html/maxdistcolor_doc.html Compares 'closed' and 'open' path sorting algorithms for 'shortest' sort type. Visualizes the paths in 3D space using different colors for closed (blue) and open (red) paths, also showing the generated colors. ```matlab clf('reset') N = 6; txt = cellstr(num2str((1:N).')); opt = {'Lmin',0.4, 'Lmax',0.5, 'bitR',7,'bitG',8,'bitB',7}; % Path Closed: [~,ucs] = maxdistcolor(N,fun, 'sort','shortest', 'path','closed', opt{:}); idx = [1:N,1]; % closed loop plot3(ucs(idx,3)-1,ucs(idx,2),ucs(idx,1)+1,'-b', 'linewidth',2) text(ucs(:,3),ucs(:,2),ucs(:,1)-7, txt, 'Color','b', 'HorizontalAlignment','center') % Path Open: [rgb,ucs] = maxdistcolor(N,fun, 'sort','shortest', 'path','open', opt{:}); hold('on') idx = 1:N; % open loop plot3(ucs(idx,3)+1,ucs(idx,2),ucs(idx,1)-1,'-r', 'linewidth',2) text(ucs(:,3),ucs(:,2),ucs(:,1)+7, txt, 'Color','r', 'HorizontalAlignment','center') % Legend and Colors: legend({'Closed','Open'}, 'Location','NorthWest') scatter3(ucs(:,3),ucs(:,2),ucs(:,1),512,rgb,'filled') grid('on') axis('equal') pause(1) ``` -------------------------------- ### Define Crystal Symmetry in MTEX Source: https://context7.com/mtex-toolbox/mtex/llms.txt This code illustrates how to define crystal symmetry for materials analysis using MTEX. It shows examples for cubic, hexagonal, and triclinic crystal systems, including defining symmetries with lattice parameters and accessing properties like point group and axes. Predefined symmetries are also demonstrated. ```matlab % Define cubic crystal symmetry (space group notation) cs_cubic = crystalSymmetry('m-3m', [3.6, 3.6, 3.6], 'mineral', 'Iron') % Define hexagonal symmetry with lattice parameters cs_hex = crystalSymmetry('6/mmm', [1.4, 1.4, 1.5], 'mineral', 'Titanium') % Define triclinic with full parameters (a, b, c, alpha, beta, gamma) cs_triclinic = crystalSymmetry('1', [5.0, 6.0, 7.0], [90, 95, 100]*degree) % Access properties cs_cubic.pointGroup % Returns: 'm-3m' cs_cubic.axes % Returns: coordinate system axes % Predefined symmetries cs_Al = crystalSymmetry('Aluminum') % Load from database ```