Is this a bug? Can it be fixed? Error in getframe (line 103) x=builtin(​'capturesc​reen', varargin{:});

Hi, (This is NOT a physics question - I just want to explain what happend before my code stopped working).
I'm doing a Quantum mechanic exercise - trying to make a movie of the time development for the probability of the wavefunction in a given potential.
Actually I had it all perfectly working yesterday - things looked like supposed and I could have stopped the assignment at that point. Curiosity then drove me to try modifying my code to solve some more problems, but I gave up and returned to my old code.
Maybe it was stupid of me, but I worked in the same script all the time. I just commented out my first code while manipulating on the 'new' code, which I deleted again in the end.
THE PROBLEM: When I removed the comment markers form the old code and tried running the script again my movie didn't work (and still doesn't). I have searched for errors long enough, but I am pretty sure, my code looks just as when it worked.
Here is my code: (I hope it is displayed properly)
L = 10;
N = 1000;
dx = 2*L/N;
xarr = (-L + dx/2):dx:(L - dx/2);
T = (-1/(2*dx^2))*(diag(ones(N-1,1),-1) + diag(ones(N-1,1),1) + -2*eye(N,N));
pos = 0;
width = 1;
% 'potentialhoadj' is a function defined seperat as:
% function f = potentialhoadj( x, pos, width )
% f = (1/width).*(1/2)*((x - pos).^2);
% end
V = potentialhoadj(xarr, pos, width);
V = diag(V);
H = V + T;
[Eigenstates, Eigenvalues] = eig(H);
Eigenvalues = diag(Eigenvalues);
maxtime = 20;
timeint = 0.1;
time = (0:timeint:maxtime).';
r = (maxtime/timeint) + 1;
for t = 1:r;
Psi2 = Eigenstates(:,1).^2 + Eigenstates(:,2).^2 + 2.*Eigenstates(:,1).*Eigenstates(:,2).*cos((Eigenvalues(2) - Eigenvalues(1))*time(t));
plot(xarr,Psi2(t));
axis([-10 10 -0.01 0.3]);
pause(0.02);
F(t) = getframe;
end
movie(F,1)
Now I don't get a move, as I did before, but just a flat coloured line not moving at all. When I close the figure Matlab returns this ERROR-message:
Error using capturescreen
Figure destroyed during getframe
Error in getframe (line 103)
x=builtin('capturescreen', varargin{:});
Error in computerovelser35 (line 45)
F(t) = getframe;
I have tried to re-install Matlab R2012b, but the situation is unchanged. When I copy the example code for the animation of the peaks function: http://www.mathworks.se/help/matlab/ref/movie.html
Then the movie does flicker (showing parts of the animation as it should be, and showing the coloured 'not moving' line as before), but this is helped away by putting in a pause(0.02) before the getframe call. This animation did however run properly without the pause before I got into all this error-troubles.
The pause unfortunately doesn't help my own movie.
Does anybody have an idea what is wrong? Can I fix the problems and make everything run as before all my troubles?

 Accepted Answer

I notice that you assign to all of Psi2 in the "for t" loop, but then plot only Psi2(t). Is that what you want? If it is, is there a reason to compute all the other entries? Are you sure you only want to plot one point at a time and then erase and draw another point? You do not have "hold on".

1 Comment

I thank you for taking time to spot my stupid error - I just got blind working on the problem for too long and changeing names on my variables I guess.
It works now.
Still I wonder, why the example surface-movie ( http://www.mathworks.se/help/matlab/ref/movie.html) didn't work without the pause(0.2), when it worked properly before my code manipulation.

Sign in to comment.

More Answers (1)

Matlab has good debugging features. See the documentation
  • Put the code in a function
function F = cssm()
your code except movie(F,1)
end
  • Note that the value of Psi2(t) is a scalar. (Psi2 is a vector.)
  • Put a break-point on the line before the loop
  • Run the function and step through the loop - inspect the values
Why expect anything else then a horizontal line?

Categories

Community Treasure Hunt

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

Start Hunting!