2013-12-11 33 views
0

我有一個函數:如何畫過像於imagesc在Matlab

A = [5,16,18,4,9; 
    9,10,14,3,18; 
    2,7,9,11,21; 
    3,7,2,19,22; 
    4,9,10,13,8] 

figure 
colormap(gray) 
imagesc(ones(15,15)) 
axis off 
for t = 1:15 
    for k = 1:15 
     text(t, k, sprintf('%c', A(t,k) + 96)) 
    end 
end 

我想畫一個位置之間的線,並從(1,2),另一說(4,5)如何我可以做到這一點,我想我可以使用劇情或線路功能,但不知道如何使用它們。

+0

注意,你的索引沒有矩陣A的大小相匹配,我相應地調整他們我代碼如下。 –

回答

1

如果我沒有得到任何錯誤:

A = [5,16,18,4,9; 
    9,10,14,3,18; 
    2,7,9,11,21; 
    3,7,2,19,22; 
    4,9,10,13,8] 

figure 
colormap(gray) 
imagesc(ones(5,5)) 
axis off 
for t = 1:5 
    for k = 1:5 
     text(t, k, sprintf('%c', A(t,k) + 96)) 
    end 
end 
hold on; 
line([1 2], [4 5]); 

結果:

Output