2016-11-27 2 views
0

私はaという行列を持っていて、pcolorと表示するたびに、自分のコンピュータから画像を特定のセルに追加したいと考えています。私は写真がある場所に写真を追加したい。画像がmatlabファイルと同じディレクトリにあれば、どうすればいいのですか?画像をファイルからpcolorセルに挿入する

コード:

a=[ 
1 0 0; 
1 1 0; 
0 0 0]; 

b=[NaN NaN NaN]; 

a = [a;b]; 
b = [b NaN]; 
b = b.'; 
a = [a b]; 

Cmap = [1 1 1]; 
colormap(Cmap); 
pcolor(a) 

私も、なぜそれがそうであるということ、それは180度行列をシフトすることをpcolorに気付いてきましたか?私はこのようなものが必要 enter image description here

: これは私が取得pcolorのプロットである。ここ enter image description here

あなたはpcolorの細胞内の画像は、私はこれを実現する方法を参照してください?

+0

[** 'subplot' **](https://www.mathworks.com/help/matlab/ref/subplot.html)、ありませんか? –

+0

'subplot'とは何ですか?リンクをありがとう、私は今しようとします。 – Jam1

答えて

0

私は自分の質問に答えるつもりです。これが他の人にも役立つことを願っています。

a=[ 
1 0 0 0; 
1 1 0 0; 
0 0 0 0; 
0 0 0 0]; 

aa = a; 
ac = aa; 

b=[NaN NaN NaN NaN]; 

a = [a;b]; 
b = [b NaN]; 
b = b.'; 
a = [a b]; 
I = imread('redirt.jpg'); 
J = imresize(I, 3, 'nearest'); 

[x , y] = size(aa); 
delete(findall(gcf,'Tag','8puzzle')) 
pos=get(gca,'position'); % getting the position 

% calculating position 
width=pos(3)/(y); 
height =pos(4)/(x); 


Cmap = [1 1 1]; 
colormap(Cmap); 
pcolor(a) 
axis off 
% loop over the positions/cells you want to place image 
for i=1:x 
    for j=1:y 
     if(aa(i,j) == 1) 
      % image position 
      axes('pos',[pos(1)+width*(i-1),pos(1)+height*(j-1),width,height], 'Tag','8puzzle'); 
      % Show image 
      imshow(J)       
     end 
     if (i == 4 && j == 4) 
      axes('pos',[pos(1)+width*(i-1),pos(1)+height*(j-1),width,height], 'Tag','8puzzle'); 
      % Show image 
      imshow('vacum.jpg') 
     end 
    end 
end 
set(gca, 'Ydir', 'reverse'); 

画像がわずかに重なりますが、表示に干渉しません。

enter image description here

関連する問題