Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在MATLAB中显示Miller索引?_Matlab_Text_Latex_Labels - Fatal编程技术网

如何在MATLAB中显示Miller索引?

如何在MATLAB中显示Miller索引?,matlab,text,latex,labels,Matlab,Text,Latex,Labels,我使用MATLAB绘制XRD分析图,其中米勒指数用于确定晶体平面方向。这些索引包含3或4个数字,负值显示在该数字上方的条形图上 在LaTeX中,它可以通过\([1\bar{1}]1]\)或\([1\overline{1}]1]\)命令来编写 为了标记XRD标准的光谱线,我使用以下命令:注意,不考虑负值 std_text_hkl(j)=text(theta{i}(j)-r,0.1,['[' hkl{j} ']'],... % position and label of j-th li

我使用MATLAB绘制XRD分析图,其中米勒指数用于确定晶体平面方向。这些索引包含3或4个数字,负值显示在该数字上方的条形图上

在LaTeX中,它可以通过
\([1\bar{1}]1]\)
\([1\overline{1}]1]\)
命令来编写

为了标记XRD标准的光谱线,我使用以下命令:注意,不考虑负值

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
既然我也想更改
'FontName'
属性,那么我如何在不使用
'explorer'、'latex'
属性的情况下自动创建负数条形图呢。至少,我希望避免标签和记号中出现不同的字体

编辑:
多亏了Magla的评论,我有了这个想法:

  • 将索引存储为3列矩阵
  • 将标签分为5个文本字段
  • 如果Miller索引为负,则在其上画一条线(文本框的顶行)
实际代码:

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's law)
      line('parent',ax_std(i),...
            'xdata',[theta{i}(j) theta{i}(j)],...
            'ydata',[0 dhkl(j,2)],... % j-th line's 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
rr=get(ax_标准(i),'xlim');%读取第i个标准的x轴限值
r=(rr(2)-rr(1))/150;%Miller索引的x偏移
对于j=1:尺寸(dhkl,1)
θ{i}(j)=asin(λ/(2*dhkl(j,1)))*360/pi();%直线的计算
%位置(布拉格定律)
行('parent',ax_std(i),。。。
“扩展数据”,[theta{i}(j)theta{i}(j)],。。。
‘ydata’,[0 dhkl(j,2)],…%j线的反射强度
'颜色',[颜色(1+mod(i-1,大小(颜色,1)),1:3)],。。。
“线宽”,3)
%米勒指数

如果θ{i}(j)>rr(1)&&θ{i}(j)这里有一段代码,在负数的顶部显示上划线。此解决方案不使用
“解释器”和“乳胶”
,因此可以选择不同的字体。请注意,代码使用一组单个文本框,每个文本框都有一个
\n
char(10)
在顶行显示下划线(
char(95)
,或
'
表示正数),在底行显示相关数字。可以选择使用两个不同的文本框来设置下划线与其数字之间的特定距离。但这段代码并不适用于所有字体(我想说90%的系统字体都很好)

下面的代码

%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
%Miller索引
米勒指数=[1-1-23-3];
%字体定义
c=列表字体;
ind_perm=randperm(长度(c));
字体名称={'Arial','Times','Courier New',c{ind_perm};
字体大小=16;
图(‘颜色’、‘w’、‘位置’、[10 10 600 1000]);
py=0.05;
对于ind_font=1:12
%字体名称
文本(0.03,py,字体名称{ind_font},'FontName',字体名称{ind_font},'FontSize',字体大小);
%打印米勒文本框
px=0.6;
对于ii=1:长度(米勒指数)

如果miller_ind(ii),我将使用第二个仅带下划线的文本字段,并将其平移或旋转以匹配目标编号。不过,这种解决方案在等间距字体(courier new,单间距)上效果很好。@Magla:Good point,
'\newline[111]
应该可以做到这一点。但是,正如您所说,仅适用于
fixedwidth
font(应该有两个空格)。您是否考虑过“使用乳胶勾号标签”的许多答案,例如。这不允许使用任何字体,但Magla提出的解决方案仅适用于您的特定请求,如果您需要显示一些复杂的latex,使用图形对象将变得不可行。您实际显示的不同字体类型实际上是相同的。哦,这是真的,至少在图的顶部。幸运的是,我在底部添加了Arial、Courier New和Times,我可以看到它们的显示方式不同。编辑在路上!事实上,所有12种字体都正确地写在Matlab的图形中。似乎“另存为eps”不起作用-我的错。图片编辑!感谢您指出这一点@Oleg Komarov。