How to show Miller indices in MATLAB?

I use MATLAB to build XRD analyzes where Miller indices are used to determine the directions of the crystallographic plane. These indices contain 3 or 4 numbers, and a negative value is displayed with a bar above this number.

In LaTeX it can be written with the command \([1\bar{1}1]\) or \([1\overline{1}1]\) .

To label the spectral lines of XRD standards, I use this command: Note that negative values ​​are not taken into account.

 std_text_hkl(j)=text(theta{i}(j)-r,0.1,['[' hkl{j} ']'],... % position and label of j-th line of i-th standard; hkl{j} holds Miller index in string format 'parent',ax_std(i),... % association with axes of i-th standard 'rotation',90,... 'fontsize',12,... 'fontname',Font); % Font holds global font setup 

How can I automate the creation of a bar over a negative number without using the 'Interpreter','latex' property, since I would also like to change the 'FontName' property. In leat, I would like to avoid different fonts in labels and ticks.

EDIT:
Thanks to Muggle's comment, I got this idea:

  • Save indexes as 3 columns of matrix
  • separate label in 5 text fields
  • if the Miller index negatively draws a line above it (top line of the text frame)

Actual code snippet:

 rr=get(ax_std(i),'xlim'); % read x-axis limits of i-th standard r=(rr(2)-rr(1))/150; % x-offset of Miller indexes for j=1:size(dhkl,1) theta{i}(j)=asin(lambda/(2*dhkl(j,1)))*360/pi(); %calculating of lines %positions (Bragg law) line('parent',ax_std(i),... 'xdata',[theta{i}(j) theta{i}(j)],... 'ydata',[0 dhkl(j,2)],... % j-th line reflection intensity 'color',[colors(1+mod(i-1,size(colors,1)),1:3)],... 'linewidth',3) % Miller indexes if theta{i}(j)>rr(1)&&theta{i}(j)<rr(2) % test if line is inside axes std_text_lbrace(j)=text(theta{i}(j)-r,0.1,'[',... 'parent',ax_std(i),... 'verticalalignment','bottom',... 'horizontalalignment','left',... 'rotation',90,... 'fontsize',12,... 'fontname',Font); pos=get(std_text_lbrace(j),'position'); ext=get(std_text_lbrace(j),'extent'); std_text_h(j)=text(pos(1),pos(2)+ext(4)/1.5,int2str(abs(hkl(j,1))),... 'parent',ax_std(i),... 'verticalalignment','bottom',... 'horizontalalignment','left',... 'rotation',90,... 'fontsize',12,... 'fontname',Font); % write 1st Miller index pos=get(std_text_h(j),'position'); ext=get(std_text_h(j),'extent') if hkl(j,1)<0 % if negative, draw line over it wdth=get(ax0,'xlim'); wdth=wdth(2)-wdth(1); set(std_text_h(j),'color','b','edgecolor','g') line('parent',ax_std(i),... 'xdata',[pos(1)-wdth/280*ext(3),pos(1)-wdth/280*ext(3)],... 'ydata',[pos(2),pos(2)+ext(4)/wdth*100],... 'color','r') end end 

I can not match the length of the string. For one digit, it is too long, for two digits it is suitable and for a larger (theoretically) it is too short. What am I doing wrong? How does MATLAB measure the 'extent' property of a rotated text property?

+6
source share
1 answer

Here is a code snippet that displays the top lines at the top of the negative digits. This solution does not use 'interpreter','latex' so that different fonts can be selected. Note that the code uses a set of single text fields, each of which has \n or char(10) to display underscores in the top line ( char(95) or ' ' for positive digits), and the associated number in the bottom line. You can select two different text fields to set a specific distance between the underline and its number. This piece of code does not work for all fonts (I would say that 90% of my system fonts work fine).

Following code

 %Miller indices miller_ind = [1 -1 -2 3 -3]; %font definition c = listfonts; ind_perm = randperm(length(c)); font_names = {'Arial','Times','Courier New',c{ind_perm}}; font_size = 16; figure('Color','w','Position',[10 10 600 1000]); py = 0.05; for ind_font = 1:12 %font name text(0.03,py,font_names{ind_font},'FontName',font_names{ind_font},'FontSize',font_size); %plot miller textbox px = 0.6; for ii = 1:length(miller_ind) if miller_ind(ii)<0 text(px,py,[char(95) char(10) num2str(-1*miller_ind(ii)) ],... 'FontName',font_names{ind_font},'FontSize',font_size,'interpreter','none'); else text(px,py,[' ' char(10) num2str(miller_ind(ii)) ],... 'FontName',font_names{ind_font},'FontSize',font_size,'interpreter','none'); end px = px + 0.03; end py = py + 0.09; end 

gives this result

enter image description here

EDIT Thank you @Oleg Komarov for his comment. Now the image is now saved as. tiff , not via .eps .

+3
source

Source: https://habr.com/ru/post/950960/


All Articles