创建用于连续测量的缓冲矩阵 [英] Create a buffer matrix for continuous measurements
问题描述
我开始在MATLAB中进行编程,在创建缓冲区矩阵时遇到一些问题.我正在尝试执行以下操作:
I'm starting programming in MATLAB and I have some problems creating a buffer matrix. I'm trying to do the following:
我不断从网络摄像头获取图像,分割后获得移动目标的质心.我需要存储质心数据进行处理,但是我不希望它占用过多的内存.例如,如果我是时间t=inf
,我正在考虑将10个时间点的数据存储在一个矩阵(如循环缓冲区)中,然后写入和擦除较旧的数据,因为我需要同时使用这两个实际数据.时间(t)和时间之前的数据(t-1).
I'm continuously obtaining an image from a webcam and after segmentation I obtain the centroid of a moving target. I need to store the centroid data for processing but I don't want it to occupy too much memory. For example, if I was a time t=inf
, I was thinking of storing 10 time points of data in a matrix, like a circular buffer, then writing and erasing the older data, because I need work with both, the actual data in time (t) and a previous data in time (t-1).
推荐答案
buffSize = 10;
circBuff = nan(1,buffSize);
for newest = 1:1000;
circBuff = [newest circBuff(1:end-1)]
end
我已经测试过了,在MATLAB中运行不需要花费很多时间.探查器找不到该代码的任何瓶颈.
I have tested this, it takes no appreciable time to run in MATLAB. The profiler did not find any bottlenecks with the code.
这篇关于创建用于连续测量的缓冲矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!