MATLAB: Storing each frame in different variable

countoptical flowstorevideo

So I have a video sequence that produces a matrix with information in about each pixel. At any given time the output can be paused and the matrix can be reviewed, however i was hoping to have each frames information stored so i can review it. There is a while loop that runs through the video so im imagining something along the lines of n = n+1 n = flowField.Magnitude But i cant get that to work, I wanted the output to then be n1,n2,n3 all containing the different info. Any help would be greatly appreciated!

Best Answer

Don't use automatically generated numbered variables. Use an array instead. Cell arrays generally do the trick, sometimes structs are a good idea as well. If the result and the number of frames are relatively small, dynamically growing the array might not be too inefficient. If not, you will have to provide more information about what the constraints of your project are.
n=0;
while n<10
n=n+1;
info{n}= flowField.Magnitude;
end
(I have taken the liberty of adapting some of Stephen Cobeldick's thoughts on this topic) Introspective programing (eval and other functions like it) is slow, and the MATLAB documentation warns specifically against it. Using eval is slow, makes debugging difficult, and removes all code helper tools (code checking, syntax hints, code completion, variable highlighting, etc.). A longer discussion can be found here. If you are not an expert and you think you need eval, there are probably better solutions to your problem. Also, if you are not an expert, you might find interesting and helpful hints on this page (and if you are an expert, you can still learn from it).
Related Question