Alternative methods for growing up matrices?

1 次查看(过去 30 天)
Hello, community,
I'm working on video frames. Starting from the first frame until the last frame of a video, my work simply includes, (for each frame) detecting objects, labeling them and storing some properties of these objects into a matrix and comparing objects of current frame to previous frame in order to detect surviving objects or new appearing objects.
The nature of the work requires keeping some memory of the past frames and that forces me to use matrices with growing size. Since videos have many thousands of frames, such growing matrix usage makes computing really slow.
Does anyone have suggestions how to handle/process such growing matrices efficiently?
(For a demo of growing matrix, I tried writing the growing matrix into a txt file, and for next iteration called the txt into a matrix array, processed the matrix array and appended it back to the same txt file as you can see from the first for loop in the code below. My goal was to free RAM memory from large matrices.
Next, I tried the same procedure by using RAM memory as you can see from the next for loop. The tic-toc performance of the second loop was far best which made me think using hard drive space for large matrices instead of RAM memory is not a good way to follow.)
KK=[1 3 5 7 9];
TT=[1 3 5 7 9];
dlmwrite('txt4.txt', KK, 'delimiter','\t','precision','%8.4f', 'newline', 'pc');
for i=1:1000
KK=dlmread('C:\Program Files\MATLAB\R2016a\bin\Test\txt4.txt');
dlmwrite('txt4.txt', KK(end,:)+i, 'delimiter','\t','precision','%8.4f', 'newline', 'pc', '-append');
end
for i=1:1000
TT(end+1,:)=TT(end,:)+i;
end
Any contribution on how to handle such growing matrices appreciated,
JD

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by