Thread Subject: how to stop animation

Subject: how to stop animation

From: Clement Lim

Date: 17 Oct, 2009 06:57:00

Message: 1 of 4

Hi, I had the following code to plot an animation surf of an audio file. However I want the animation to stop once the audio had stopped playing. Can anyone advise me? tks

[x,fs]=wavread('Equalized_all.wav');

Fs=fs/(1024*1024);
temp = [0.5*Fs, 0.9*Fs, 2*Fs^2, ...
    1.5*Fs, 4*Fs, 5*Fs, 6*Fs, ...
    5*Fs^2, 5*Fs^2, 7*Fs, 8*Fs, 9*Fs];

% Eigenfunctions
for k = 1:12
   L{k} = membrane(k);
end

% Get coefficients from eigenfunctions.
for k = 1:12
    c(k) = L{k}(25,23)/3;
end
 
% Set graphics parameters.
fig = figure;
set(fig,'color','white')
x = (-15:15)/15;
L{1}(L{1}==0)=NaN;
h = surf(x,x,L{1});
[a,e] = view;
view(a+90,e);
axis([-1 1 -1 1 -1 1]);
caxis(26.9*[-1.5 1]);
colormap hsv;
axis on

% Run
t = 0;
dt = 0.025;
set(fig,'userdata',dt)
while ishandle(fig)
    % Coefficients
    dt = get(fig,'userdata');
    t = t + dt;
    s = c.*sin(sqrt(temp)*t);

    % Amplitude
    A = zeros(size(L{1}));
    for k = 1:12
      A = (A + s(k)*L{k})-Fs;

    end

    % Velocity
    s = temp .*s;
    V = zeros(size(L{1}));
    for k = 1:12
      V = V + s(k)*L{k};
    end
    V(16:31,1:15) = NaN;

    % Surface plot of height, colored by velocity.
    set(h,'zdata',A,'cdata',V);
    drawnow

Subject: how to stop animation

From: Luigi Giaccari

Date: 19 Oct, 2009 09:48:01

Message: 2 of 4

"Clement Lim" <clementlim@singnet.com.sg> wrote in message <hbbprs$4e5$1@fred.mathworks.com>...
> Hi, I had the following code to plot an animation surf of an audio file. However I want the animation to stop once the audio had stopped playing. Can anyone advise me? tks
>
> [x,fs]=wavread('Equalized_all.wav');
>
> Fs=fs/(1024*1024);
> temp = [0.5*Fs, 0.9*Fs, 2*Fs^2, ...
> 1.5*Fs, 4*Fs, 5*Fs, 6*Fs, ...
> 5*Fs^2, 5*Fs^2, 7*Fs, 8*Fs, 9*Fs];
>
> % Eigenfunctions
> for k = 1:12
> L{k} = membrane(k);
> end
>
> % Get coefficients from eigenfunctions.
> for k = 1:12
> c(k) = L{k}(25,23)/3;
> end
>
> % Set graphics parameters.
> fig = figure;
> set(fig,'color','white')
> x = (-15:15)/15;
> L{1}(L{1}==0)=NaN;
> h = surf(x,x,L{1});
> [a,e] = view;
> view(a+90,e);
> axis([-1 1 -1 1 -1 1]);
> caxis(26.9*[-1.5 1]);
> colormap hsv;
> axis on
>
> % Run
> t = 0;
> dt = 0.025;
> set(fig,'userdata',dt)
> while ishandle(fig)
> % Coefficients
> dt = get(fig,'userdata');
> t = t + dt;
> s = c.*sin(sqrt(temp)*t);
>
> % Amplitude
> A = zeros(size(L{1}));
> for k = 1:12
> A = (A + s(k)*L{k})-Fs;
>
> end
>
> % Velocity
> s = temp .*s;
> V = zeros(size(L{1}));
> for k = 1:12
> V = V + s(k)*L{k};
> end
> V(16:31,1:15) = NaN;
>
> % Surface plot of height, colored by velocity.
> set(h,'zdata',A,'cdata',V);
> drawnow

comute the execution time fo the audio before launching the simulation.

Then use the matlab timer (see " tic" "toc" or the "time" command) to check at every iteration if the time has expired.


http://www.advancedmcode.org

Subject: how to stop animation

From: Clement Lim

Date: 20 Oct, 2009 12:26:03

Message: 3 of 4

Hi, Thanks for the suggestion. I had read the doc but still had no idea how can i put it into my script. Can you kindly assist or advise me in this? your assistance would be greatly appreciated.

Rgds

Subject: how to stop animation

From: Luigi Giaccari

Date: 24 Oct, 2009 11:02:02

Message: 4 of 4

"Clement Lim" <clementlim@singnet.com.sg> wrote in message <hbka8r$h8e$1@fred.mathworks.com>...
> Hi, Thanks for the suggestion. I had read the doc but still had no idea how can i put it into my script. Can you kindly assist or advise me in this? your assistance would be greatly appreciated.
>
> Rgds

Nothing is easier:


maxtime=(tim lengh of the animation)

tic
for i=1:10000 %main loop

 operation

 if toc>maxtime
 break%end simulation
end

end


notice that "toc" counts the time from the last "tic", so tic goes out the loop and toc inside.

http://www.advancedmcode.org

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com