tags:

views:

341

answers:

2

I read the: How to create a buffer matrix in MATLAB for continuous measurements?, question. I wanted to know if its possible to store values in sequence instead of in reverse as in the question, without resorting to fliplr (flip left to right) after each iteration?

+2  A: 

Front to back:

buffSize = 10;
circBuff = nan(1,buffSize);
for newest = 1:1000;
    circBuff = [circBuff(2:end) newest]
end

circBuff = 991 992 993 994 995 996 997 998 999 1000

Back to front:

buffSize = 10;
circBuff = nan(1,buffSize);
for newest = 1:1000;
    circBuff = [newest circBuff(1:end-1)]
end

circBuff = 1000 999 998 997 996 995 994 993 992 991

Todd
+2  A: 
buffSize = 10;
circBuff = nan(1,buffSize);
for newest = 1:1000;
    circBuff = [circBuff(2:end), newest]
   %circBuff = [newest circBuff(1:end-1)] %reverse direction

end

I have tested this, it takes no appreciable time to run in MATLAB. The profiler did not find any bottlenecks with the code.

MatlabDoug

related questions