Matlab的:Videowriter创建了数字只有部分视频 [英] Matlab: Videowriter creates video with only section of figure

查看:976
本文介绍了Matlab的:Videowriter创建了数字只有部分视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了绘制火卫一,并MEX绕火星飞船MAVEN的轨道动画的脚本。我想这个动画视频。它的工作原理几乎是完美的,但由于某些原因产生的视频是在Matlab动画的变焦和我想不通为什么。

I made a script that plots an animation of the orbit of Phobos, MEX and MAVEN spacecraft around Mars. I want a video of this animation. It works almost perfect but for some reason the video created is a zoom of the animation in Matlab and I can't figure out why.

这是我的code(忽略与cspice一切,这是一个工具箱接收对象在空间中的位置):

This is my code (Ignore everything with cspice, this is a toolbox to receive positions of objects in space):

clear

%Load kernels
cspice_furnsh( 'de421.bsp' )
cspice_furnsh( 'MAR085.BSP' )
cspice_furnsh( 'maven_v03.tf' )
cspice_furnsh( 'MEX_130305_STEP.TSC' )
cspice_furnsh( 'MEX_V11.TF' )
cspice_furnsh( 'MVN_SCLKSCET.00000.tsc' )
cspice_furnsh( 'NAIF0010.TLS' )
cspice_furnsh( 'ORMF_______________00880.BSP' )
cspice_furnsh( 'PCK00010.TPC' )
cspice_furnsh( 'spk_m_141027-151027_110526.bsp')
cspice_furnsh( 'ORMM__150301000000_01138.BSP' )

% Flyby 09 APR 2015    
    ETbegin = cspice_str2et( '2015-04-09T06:30:00' );
    ETend = cspice_str2et( '2015-04-09T14:10:00' );

% Generation of calculation input array
    interval_ET=[ETbegin:1:ETend];

% Computation of positions of MAVEN, MEX and Phobos in reference to Mars
    position_MAVEN_Mars = cspice_spkpos...
        ( 'maven', interval_ET, 'J2000', 'none', 'mars' );
    position_MEX_Mars = cspice_spkpos...
        ( 'mex', interval_ET, 'J2000', 'none', 'mars' );
    position_Phobos_Mars = cspice_spkpos...
        ( 'phobos', interval_ET, 'J2000', 'none', 'mars' );

MEX_x = position_MEX_Mars(1,:);
MEX_y = position_MEX_Mars(2,:);
MEX_z = position_MEX_Mars(3,:);
MAVEN_x = position_MAVEN_Mars(1,:);
MAVEN_y = position_MAVEN_Mars(2,:);
MAVEN_z = position_MAVEN_Mars(3,:);
PHOBOS_x = position_Phobos_Mars(1,:);
PHOBOS_y = position_Phobos_Mars(2,:);
PHOBOS_z = position_Phobos_Mars(3,:);

writerObj = VideoWriter('video_flyby.avi');
writerObj.FrameRate = 30;
writerObj.Quality = 100;
open(writerObj);

figure
plot3(0,0,0,'ro-',MEX_x,MEX_y,MEX_z,'b',...
                  MAVEN_x,MAVEN_y,MAVEN_z,'r',...
                  PHOBOS_x,PHOBOS_y,PHOBOS_z,'k');
legend('Mars','MEX','MAVEN','Phobos');
xlabel('X-axis (km)');
ylabel('Y-axis (km)');
zlabel('Z-axis (km)');
xlim([-20000 20000]);
view([47.5 32]);
grid on;
hold on;
m1 = plot3(MEX_x(1),MEX_y(1),MEX_z(1),'b*','MarkerSize',10);
m2 = plot3(MAVEN_x(1),MAVEN_y(1),MAVEN_z(1),'r*','MarkerSize',10);
m3 = plot3(PHOBOS_x(1),PHOBOS_y(1),PHOBOS_z(1),'k*','MarkerSize',10);
axis tight
set(gca,'nextplot','replacechildren');
set(gcf,'Renderer','zbuffer');
for n = 1:100:numel(PHOBOS_x)
    set(m1, 'XData', MEX_x(n), 'YData', MEX_y(n), 'ZData', MEX_z(n));
    set(m2, 'XData', MAVEN_x(n), 'YData', MAVEN_y(n), 'ZData', MAVEN_z(n));
    set(m3, 'XData', PHOBOS_x(n), 'YData', PHOBOS_y(n), 'ZData', PHOBOS_z(n));
    drawnow;
    frame = getframe;
    writeVideo(writerObj,frame);
end

close(writerObj);

% Unload kernels
cspice_kclear;

这是什么结果看起来像在Matlab。

This what the result looks like in Matlab.

而这正是视频的全画幅模样。

And this is what a full frame of the video looks like.

推荐答案

如果您使用的getFrame 不带参数,只捕获当前轴。
创建人物的处理,并给它作为参数传递给的getFrame 。这样你将捕获实际数字的所有内容。

If you use getframe without an argument, you only capture the current axes. Create a handle of the figure and give it as an argument to getframe. This way you will capture all the contents of the actual figure.

这是影响了两行,只是为了告诉你的原则是:

These are the two lines affected, just to show you the principle:

fh = figure;
frame = getframe(fh);

这篇关于Matlab的:Videowriter创建了数字只有部分视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆