[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
octave not updating plot using drawnow() in a loop
From: |
Nasser M. Abbasi |
Subject: |
octave not updating plot using drawnow() in a loop |
Date: |
Tue, 17 Jul 2012 08:09:55 -0500 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 |
I am using octave on Linux. I wrote this small toy example which
runs fine on Matlab on windows. But when I run it in octave,
the plot is not being updated.
i.e. the plot does show up, but the pendulum should start moving.
on octave the drawnow() is not having an effect as it does on Matlab.
It also seems to hang, as I leave it running and it never finished.
I was wondering if someone who has octave can try it and see if it
runs ok on their system? I am using octave 3.2.4 on linux. Here is
the code, put it all in file called ex1.m and type ex1 from octave to run it.
thank you
--Nasser
---- ex1.m ----------------------
function ex1
t=0:0.0001:10;
L0=4;
IC=[L0 0 0.8*pi/2 0];
options = odeset('OutputFcn',@output);
[t,x]=ode45( @rhs, t, IC, options);
plot(t,x);
xlabel('t'); ylabel('x');
end
function status= output(t,x,z)
L0=4;
status = false;
if isempty(t)
status = true;
else
vx=x(1,1).*sin( x(3,1) );
vy=-x(1,1).*cos(x(3,1));
plot(vx, vy,'o');
line([0 vx],[0 vy]);
xlim([-1.3*L0 1.3*L0]);
ylim([-1.3*L0 1.3*L0]);
drawnow();
pause(0.1);
end
end
function xdot=rhs(t,x)
g=9.8;
m=30;
f=1;
L0=4;
k=m*(2*pi*f)^2;
xdot=[x(2);
x(1)*x(4)^2-g*cos(x(3))-k/m*(x(1)-L0);
x(4);
-g/x(1)*sin(x(3))-2*x(2)*x(4)/x(1)];
end
--------------------
- octave not updating plot using drawnow() in a loop,
Nasser M. Abbasi <=