I have this function where I use an array as a FIFO queue (i.e., put elements in it and process them using a first-in first-served approach). In particular, I call this array a MsgQueue as it holds messages. 

The MsgQueue is used when a new msg is sent (event), which triggers the execution of the *handleMsgSent()* method, which I show next

```
function handleMsgSent(this, msg)

        this.MsgQueue = [this.MsgQueue msg];

        while(numel(this.MsgQueue) > 0)
            m = this.MsgQueue(1);
            this.MsgQueue = this.MsgQueue(2:end); % <----- OPTION A

            % DO WHATEVER WITH THE MESSAGE

            %this.MsgQueue(1) = []; % <------ OPTION B
        end            
    end

```

As you can see I have marked the code with **OPTION A** and **OPTION B** comment. So, the point is option B ends up with the "Matrix Index is out of range for deletion" error while option A works (apparently) perfectly fine, with no errors.

Can anyone help me to understand the difference? Well, I understand that option A is not deleting anything but just "discarding" the first element of the array but, why does option B fails in deleting if there is at least one element in MsgQueue?