Hello everyone,
I am trying to replicate the approach given in this example: https://es.mathworks.com/matlabcentral/answers/78345-make-a-smooth-animation
I want, as him, to not to show each frame in iteration of a loop, and get directly the .avi video. I have tried to addapt directly the code for my case, but it seems that avifile function does not work in my MatLab version (the last one). So I have seen that the role of avifile has been replaced by VideoWriter. The problem is… which function plays the role of addframe in the VideoWriter environment? I let you here my example of the code adapted directly from the aforementioned post
physical_time_inelastic=[0:1:30];spatial_grid=[0:1:100];data_set_inelastic=rand([length(spatial_grid),4,length(physical_time_inelastic)]);avi_mx_inelastic=VideoWriter('mx_Magnetization_Component_Evolution_Inelastic.avi');u9=figure('visible','off');for i=1:length(physical_time_inelastic) plot(spatial_grid.*(10^6),data_set_inelastic(:,2,i),'-b','LineWidth',2) xlabel('Track position, $x \, \, \left( \mu\mathrm{m} \right)$','FontSize',14,'interpreter','latex') ylabel('$x$-{\it th} magnetization components, $m_x$','FontSize',14,'interpreter','latex') t9=title(['Inelastic collision, $t=$',num2str(physical_time_inelastic(i).*(10^(12))),' ps'],'FontSize',14,'interpreter','latex') set(t9,'interpreter','latex','FontSize',12) set(u9,'Units','Inches'); posu9=get(u9,'Position'); set(u9,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[posu9(3),posu9(4)]) avi_mx_inelastic=addframe(avi_mx_inelastic,u9);endavi_mx_inelastic=close(avi_mx_inelastic)implay('mx_Magnetization_Component_Evolution_Inelastic.avi')
Also I would want to display in the title of each frame which is the value of physical_time_inelastic variable. It works as it is, but I would prefer the number to be in scientific notation. Any suggestion?
Best Answer