2017-05-08 72 views
1

我想在矩阵中读取图中的特定单元格的方向。如何使用'乳胶箭头符号'在图中创建对角箭头?

在附图中,我可以创建左方向箭头,但我没有得到如何在西南方向插入对角箭头。

enter image description here

显然,latex arrow symbol工作正常的左箭头,右箭头,箭头向上和向下箭头,但未能为斜箭头。

在附图中我需要通过青色细胞向西南方向插入箭头。这个怎么做?

这里是我想剧本,

for row=1:size(data,1) 
    for col=1:size(data,2); 

     if data(row,col)==1 
      rectangle('Position',[col-0.5 row 1 1], 'FaceColor','y','EdgeColor','k', 'LineWidth', 0.1) 
      text(col-0.95,row+0.6,'\leftarrow', 'fontsize', 6); 

     elseif data(row,col)==2 
      rectangle('Position',[col-0.5 row 1 1], 'FaceColor','c','EdgeColor','k', 'LineWidth', 0.1) 
      text(col-0.95,row+0.6,'\swarrow', 'fontsize', 6); 

     else 
      rectangle('Position',[col-0.5 row 1 1], 'FaceColor','w','EdgeColor','k', 'LineWidth', 0.1)    
     end 

    end 

    set(gca,'Visible','off') 
end 

编辑: Annotation选项会增加复杂性,需要为每一个问题箭头的位置。如果可以使用乳胶箭头符号,问题会变得更容易。

+0

你考虑到刚刚绘制矢量而不是使用Latex文本呢? – Bernhard

+0

不,我不知道。你能再详细一点吗? – Mario

+0

'annotation'可以做这项工作 –

回答

1

如上所示,您可以使用quiver来绘制箭头。此外,pcolor是绘制所有矩形并为它们着色的更好方法。

下面是使用他们都创造一些像你想要什么代码的例子:

data = randi(3,10)-1; % some random data 
% plot the rectangles: 
pcolor([data data(:,end); 
     data(end,:) 0]) 
% set the colors to w-y-c: 
colormap([1 1 1; 
    1 1 0; 
    0 1 1]); 
[r, c] = ndgrid(1:size(data,1),1:size(data,2)); % a grid of all the cells 
% logical indexing for the arrows: 
leftarrow = (data==1); 
swarrow = (data==2); 
% plot all the arrows in black: 
hold on 
quiver([r r]+0.1,[c c]+0.5,[-leftarrow.' -swarrow.'],... 
    [zeros(size(data)) -swarrow.'],'AutoScaleFactor',0.5,'Color','k') 
hold off 
set(gca,'Visible','off') 

和典型的结果是: pcolor & quiver