MATLAB: Remove First Element of Array And Add Element to the End (FIFO array)

arrayfifo

Hi I'm trying to modify an array so that I remove the first element of an array completely (ie decrease the size of the array). Then once I've done that I would like to add a new element (increase the size of the array).
For instance:
>>array = {1,2,3,4}
>>remove element 1
>> array = {2,3,4}
>>add element
>> array = {2,3,4,5}
What I'm really trying to do is create a sort of FIFO array. I've seen some other examples… but most of them don't delete the size of the array then increase it (just delete values). Is there an easy way to do this?

Best Answer

One approach:
array = {1,2,3,4};
array = array(2:end)
array{end+1} = 5