2016-02-26 101 views
0

我想創建4個子圖,每個包含16個數字。每個圖形都是矩陣GW的一個維度。即GW(:,:,1)是第一個圖像。 這是我在第一個子圖中的前16個圖像的for循環。我應該如何修改for循環來獲得3個更多的子圖? 第一個子圖應該包含前16個圖像,第二個子圖應該包含第二個16個圖像,依此類推。隨着下面的循環,我得到了所有四個子圖的前16個圖像。如何分別繪製一個X * Y * Z(3D)矩陣的matlab?

for i=1:4 
     figure(i); 
     hold on; 

     for jj = 1:16 
       subplot (4,4,j) 
       imshow (GW(:,:,j)); 
     end 
end 

回答

0

你只需要修改你如何訪問GW的第三維。試試這個:

num_figures = 4; % because I dont like magic numbers in the code 
subplots_per_figure = 16; % same here 
for i=1:num_figures 
     figure(i); 
     hold on; 

     for j = 1:subplots_per_figure 
       subplot (4,4,j) 
       imshow (GW(:,:,j+(i-1)*subplots_per_figure)); 
     end 
end