Matlab: Videowriter creates video with only sectio

2019-08-16 14:49发布

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.

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;

This what the result looks like in Matlab. enter image description here

And this is what a full frame of the video looks like. enter image description here

1条回答
趁早两清
2楼-- · 2019-08-16 15:25

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);
查看更多
登录 后发表回答