Search code examples
matlabqueuefifocell-array

How to create a FIFO queue to a cell array of cell arrays in MATLAB?


Let's say that we have a cell array of cell arrays, called Q, a <1x3256 cell>, and each cell is a cell array like this one below, for example:

Q{1}{1}

ans =

 0   451     0

etc. The problem is, that i want to create a FIFO queue in order to "clear" every cell and send the contents of each cell to another function (in the above cell the values 0 451 0), one by one each time. It is essential to use a FIFO queue and only, because it is a part of an implementation of a specific algorithm. If possible, i would rather not to use Java in Matlab, like LinkedList, as i have already read in other topics.

How could i do that FIFO queue with this cell array of cell arrays?Any ideas? Any help would be really appreciated.


Solution

  • Take the first value

    input = Q(1);  % or Q{1} depending on requirements
    

    Clear the first value:

    Q(1) = []; % Q will now be, e.g. 1x3255 cell
    % Q(1) is now the old Q(2)
    

    This needs to be () not {} - the latter will empty the contents of Q(1) only (Q will remain 1 x 3256).

    To add additional values to the end of the queue:

    Q(end+1) = newdata;