2015-10-27 39 views
1

我使用了一個名爲ind2patch的函數來製作一個3D塊,其中包含三維中的一些較小的塊。每個小塊都有一個用顏色表示的值。一個典型的情節是這樣的一個:從一組3D圖創建視頻

typical plot

現在我想顯示值與使用視頻,這些小塊的時間的變化(即顏色)。我有不同時刻的數據,但我只知道如何通過閱讀不同的文件在不同時間繪製圖表。有沒有辦法將情節結合到視頻中,或直接以視頻的形式繪製圖表?

這裏是我的代碼:

clear; close all; clc; 
fig = figure(1); 
set (fig, 'Units', 'normalized', 'Position', [0,0,1,1]); 
fig_color='w'; fig_colordef='white'; 
cMap=jet(256); 
faceAlpha1=1; 
faceAlpha2=0.65; 
edgeColor1='none'; 
edgeColor2='none'; 
NumBoxX=100;%box number in x direction 
NumBoxY=100;%box number in y direction 
NumBoxZ=5;%box number in z direction 

fid = fopen('rho 20950.dat','r'); 
datacell = textscan(fid, '%f%f%f%f%f%f%f%f'); 
fclose(fid); 

all_data = cell2mat(datacell); 

M=zeros(NumBoxX,NumBoxY,NumBoxZ); 

for i=1:NumBoxX    
    for j=1:NumBoxY   
     for k=1:NumBoxZ  
      num=k+NumBoxZ*(j-1)+NumBoxZ*NumBoxY*(i-1); 
      M(i,j,k)=all_data(num,4); 
     end 
    end 
end 

indPatch=1:numel(M); 
[F,V,C]=ind2patch(indPatch,M,'v'); 

title('\sigma_{xy} in different cells','fontsize',20); 
xlabel('y','fontsize',20);ylabel('x','fontsize',20); zlabel('z','fontsize',20); hold on; 
set(get(gca,'xlabel'),'Position',[5 -50 30]); 
set(get(gca,'ylabel'),'Position',[5 50 -15]); 
set(get(gca,'zlabel'),'Position',[64 190 -60]); 
patch('Faces',F,'Vertices',V,'FaceColor','flat','CData',C,'EdgeColor','k','FaceAlpha',0.5); 
axis equal; view(3); axis tight; axis vis3d; grid off; 
colormap(cMap); caxis([min(M(:)) max(M(:))]); 
cb = colorbar;          

set(get(cb,'title'),'string','Stress (MPa)','fontsize',20); 

lbpos = get(cb,'title'); % get the handle of the colorbar title 
%set(lbpos,'Units','data');% change Units to data 
%pos = get (lbpos,'position'); % get position of the colorbar title 
set(lbpos,'units','normalized','position',[0,1.04]); 

MyAxes=gca; 
set(MyAxes,'Units','Normalized','position',[0.05,0.1,0.8,0.8]); 
zoom(1.85); 
+0

不要use'jet'如色彩表:(使用感知均勻colromaps! –

+0

@Ander Biguri,你是說那個顏色表適用於所有具有不同值的地塊?我是新用戶,不太確定感知均勻的色彩地圖。 –

+1

有可能成爲垃圾郵件,請使用:http://uk.mathworks.com/matlabcentral/fileexchange/51986-perceptually- uniform-colormaps。知覺上統一的色彩圖是一個更好地表示數據的色彩圖。在人的眼睛上感知一種類似的金元音。 Jet很厭倦。 –

回答

4

你可以做這樣的事情:

  1. 循環每一個補丁,並抓住它的映像。
  2. 插入圖像插入一個矩陣
  3. 轉換圖像矩陣成電影使用immovie

% // Create a matrix to hold your images A = zeros(row,col,numOfColours, numOfFrames);

其中row是行數和col被列在數一個圖像。

循環播放您的補丁並創建單個圖像的視頻。

for n=1:numOfPatches 
    imshow(patches(:,:,n)) % // display the image 
    frame = getframe(gcf) % // get the current figure window 
    im = frame2im(frame); % // convert it to an image 
    A(:,:,1:3,n) = im;  % // Insert the image into the matrix 
end 

的你可以用immovie將其轉換爲電影

mov = immovie(RGB); 
movie(mov); % // play the movie 
+1

打我一秒。只需稍加說明:不是將幀轉換爲圖像然後回到電影,而只需調用'mov(n)= getframe(gcf)'。 (順便說一下,我認爲它應該是'A(:,:1:3,n)',否?) – hbaderts

+0

是的,應該是'A(:,:,1:3,n)'。謝謝... – kkuilla

+0

@kkuilla,很快就會試用。可能會有一些後續問題。提前致謝。 –