2013-07-01 84 views
0

**我想出了如何创建电影,以便代码已更改为反映正确的电影,以防将来对任何人有用。 此脚本创建eqdconic地图的电影并将其保存为avi格式。电影将贯穿1255帧。它还在图像上的某个点绘制一个点,在电影上放置一个改变的标题,以显示月份的运行情况,并在右侧显示一个颜色条。MATLAB创建电影

一些使用的变量是在别处创建的。创建它们的代码已被排除在外以压缩代码(并且因为它们不会对除我以外的任何其他人有用)。

% Create movie 
    nFrames = 34; % Number of frames 

for k = 1:nFrames 
    % Eqdconic script  
    % Define figure and axes 
    fg1 = figure(1); 
    axesm('MapProjection','eqdconic', 'MapParallels', [], 'MapLatLimit',[-80 -59],'MapLonLimit',[190 251]) % 60-70S and 120-160W 
    framem on; gridm on; mlabel on; plabel on; hold all; 

    % Plot data 
    frame = dataPoint_movie(:,:,k); 
    image = contourfm(lat,lon,frame, 'LineStyle', 'none'); 

    hold on 

    % Plot dot  
    plotm(-66.75,224,'k.','MarkerSize',30); 

    % Colorbar 
    caxis([0 100]); 
    h = colorbar; 
    ylabel(h,'Percent'); 

    % Title: Days 1:1258 inclusive. 20100101 to 20130611 
    date = datenum(2009, 12, 31) + k; % Convert t into serial numbers 
    str = datestr(date, 'mmm yyyy'); % Show in the format mmm yyyy so title changes only once a month 
    title(str); 

    mov(k) = getframe(gcf); % gca would give only the image. gcf places the title and other attributes on the movie. 
end 

close(gcf) 

% % Save as AVI file 
movie2avi(mov, 'SeaIceConcentration.avi', 'compression', 'none', 'fps', 2); 
+0

'for t = 1:12'-loop生成一个图还是空轴? – Schorsch

+0

基于['getframe'-documentation](http://www.mathworks.com/help/matlab/ref/getframe.html),你是否试过'A(i)'而不是'A(:,:我)'? – Schorsch

+0

为什么从'i = 1:numframes'循环,然后从't = 1:1258'再次循环每个'i'? – Schorsch

回答

1

我更喜欢将我的电影从matlab导出到.avi文件。

前的for循环,初始化你的电影:

vidObj = VideoWriter('Movie.avi'); 
vidObj.FrameRate=23; 
open(vidObj); 

然后让你的框架在for循环:

A = getframe; 
writeVideo(vidObj,A); 

(注意,我不是节约每一帧矩阵,所以A是m×n矩阵)

然后写出你的电影后的for循环

close(vidObj); 

该电影将在您当前的工作目录中。您可以使用quicktime或其他avi播放器打开。要更改电影的帧速率(速度),请编辑第二行代码。 23 fps是一个很好的流畅的电影帧率。

+1

我的意思并不是要嗤之以鼻,但这些是真正独立的问题,而这些论坛的目的不是调试你的特定代码。 对于日期,尝试查看[这篇文章](http://stackoverflow.com/questions/16502693/date-from-multiple-strings-in-matlab)。 对于图的大小调整,你可以使用set命令来做到这一点,如[这里说明](http://stackoverflow.com/questions/13478132/how-to-reduce-the-borders-around-subplots-in- MATLAB和-subaxis-犯规工作/ 16922127#16922127)。 – mrsoltys

1

检查报表的一致性:

A = dataPoint(:,:,t); 

A(i) = getframe; 

一个被覆盖所有的时间,这样你会得到最好的最后一帧。