Optimization on movie command

조회 수: 1 (최근 30일)
NGUYEN  Quang Hung
NGUYEN Quang Hung 2015년 3월 18일
답변: John 2015년 3월 18일
Hi all, I use the movie command to make a animation on my plot: like this
close all;
clear all
clc;
figure('Renderer','zbuffer')
psy_0= linspace(1,20, 20);
s=size(psy_0);
psy_s=psy_0/1000;
z_mat=1;
con_mat=0.1;
h=10e-9;
e = 1.602e-19;
k_b = 1.381e-23;
T = 298;
Na = 6.022e23;
epsilon = 6.95e-10;
kappa = (z_mat*sqrt(con_mat)*1e10)/3.04
xi= linspace(0,h*kappa);
x= linspace(0,h);
y= size(x);
C= exp(-xi);
D=zeros(1,s(2));
z=zeros(1,s(2));
A=zeros(s(2),y(2));
B=zeros(s(2),y(2));
psy_seul_t=zeros(s(2),y(2));
set(gca,'NextPlot','replaceChildren');
F(20) = struct('cdata',[],'colormap',[]);
for j = 1:1:s(2)
z(j)=(e*psy_s(j)*z_mat)/(k_b*T);
D(j)= exp(z(j)/2);
A(j,:)= D(j) + 1 + (D(j) -1)*C;
B(j,:)= D(j) + 1 - (D(j)-1)*C;
psy_seul_t(j,:)= 2*log(A(j,:)./B(j,:));
psy_seul(j,:)= (psy_seul_t(j,:)*k_b*T)/e/z_mat;
psy_lin(j,:)= psy_s(j)*exp(-kappa*x);
hold all
plot(x,psy_lin(j,:),'r');
plot(x,psy_seul(j,:),'b');
axis([0 1e-8 0 0.025]);
F(j) = getframe;
end
It works well, however, the animation's speed is to high, so how can I reduce the animation's speed.
Secondly, I want to make a counter of j appear on the plot for each loop, does it possible?
And finally, how can I export to an . avi?
Best regards

답변 (1개)

John
John 2015년 3월 18일
Hi Nguyen. you can set the frames-per-second for playback with the movie function. The function signature is something like this: movie(stack_name, number_of_times_to_repeat, frames_per_second)
When you playback with the movie function, set the frames_per_second to a small value between 1 and 8.
When I add the following to the end of your snippet, I get a pleasant animation of F:
movie(F, 1, 1)
Yes, you can display the loop number. Look up the text function and pay attention to the String property of the text object. Use it before getframe.
And yes, you can export to a .avi. You can use the VideoWriter function to create a video from the frame data in F (look at your code). Pay attention to the frame rate again. Also be sure to pass it the cdata field of each slice in F.
BTW please select this as an accepted answer if you found it useful.

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by