2016-11-27 61 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) 

我也一直與pcolor注意到,這180度轉變的矩陣,爲什麼會這樣呢? 這是令pColor情節,我得到: enter image description here

我需要的是這樣的: 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