Matlab command window is blocked / or busy when I plot an animation

3 vues (au cours des 30 derniers jours)
Karthuk
Karthuk le 18 Juin 2013
Commenté : raym le 13 Avr 2018
Hello, Was just wondering if Matlab supports the below ?
below is the small snippet (say), I plot a figure and try to acheive animation in a while(1) loop:
function Example()
x=-5:.2:5;
y=sin(x);
h=plot(x,y);
axis([-2*pi 2*pi -1 1])
axis square
grid off
set(h,'EraseMode','xor','MarkerSize',18)
while(1)
for t=2:.1:7
drawnow
y=sin(x)*exp(-t);
set(h,'YData',y)
pause(0.05)
end
end
So I' am able to achieve th animation but can I do that witout locking the command window ? I don't want to block the command window. Could some one help me out on this please ?
  1 commentaire
Chetan Aswathanarayana
Chetan Aswathanarayana le 18 Juin 2013
It would be Interesting, if somebody knows the answer for this one ?

Connectez-vous pour commenter.

Réponses (4)

Sean de Wolski
Sean de Wolski le 18 Juin 2013
Use a timer.
doc timer
I've written quite a few answers that have examples in them if you search through Answers' history.

Karthuk
Karthuk le 18 Juin 2013
Any help would be much appreciated.
Thanks
  1 commentaire
Jan
Jan le 18 Juin 2013
Please do not bump your question by posting a pseudo-answer. If the readers know an answer and find the time for typing it, they will do it voluntarily. But when the question appears on topmost position again, although there is no new information, the time for reading the question another time is wasted. Therefore I'd suggest to limit bumping for a time delay of 24, better 48 hours.

Connectez-vous pour commenter.


Jan
Jan le 18 Juin 2013
Matlab is a single threaded application (in theory). Using the TIMER Sean has suggested is a method to run a thread nearly in parallel. But the esiest way is to open another Matlab instance:
!matlab &
  1 commentaire
raym
raym le 13 Avr 2018
Yes. The pause(i) blocks all the command window and blobks all running code.

Connectez-vous pour commenter.


Chetan Aswathanarayana
Chetan Aswathanarayana le 19 Juin 2013
Thanks Sean, Picked up something from this today.
@Karthuk: Maybe this might help and was what you were looking for:
function Example()
x=-5:.2:5;
y=sin(x);
h=plot(x,y);
axis([-2*pi 2*pi -1 1])
axis square
grid off
set(h,'EraseMode','xor','MarkerSize',18)
t = timer('ExecutionMode','fixedRate',... %# Fire at a fixed rate
'Period',0.25);
t.TimerFcn = {@Do_It,h,x};
start(t);
end
function Do_It(obj,event,h,x)
for t=2:.1:7
drawnow
y=sin(x)*exp(-t);
set(h,'YData',y)
pause(0.04)
end
end
  1 commentaire
Sean de Wolski
Sean de Wolski le 19 Juin 2013
I would lower the timer's period and then remove the for-loop from DO_it. You can calculat T based on the event's 'TasksExecuted' property.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by