# Append elements to matrix in Matlab

I want to make a matrix like this:

```n rows x 2 columns

22.3 18.3
22.4 18.4
22.5 18.3
22.4 18.3
22.2 18.6
```

In this case I have 5 rows by 2 columns

But I need to append a new row dynamically, removing the first based in a given window I want.

e.g. I have a window of N elements in row, when I append the new row in the matrix, I must remove the first one.

In the above example, a window of 5 rows: If I need to input (append) the new row: 22.8 17.1 the row will become like this:

```22.3 18.3
22.4 18.4
22.5 18.3
22.4 18.3
22.2 18.6
22.8 17.1
```

There are 6 rows, I need to remove the first one. After that the row becomes like this (5 rows):

```22.4 18.4
22.5 18.3
22.4 18.3
22.2 18.6
22.8 17.1
```

My question: - how to append a new row in matlab? - how to remove a new row in matlab?

I saw that in matlab It's possible to handle matrix vectors and cells.

E.g I achieved What I want doing that:

```messageArr = [];
messageArr{end+1} = 23.01
messageArr{end+1} = 23.02
messageArr = messageArr.';%'//
messageArr{end+1} = 23.03
messageArr{end+1} = 23.04
messageArr{end+1} = 23.04
messageArr{end+1} = 23.04
messageArr{end+1} = 23.04
messageArr{end+1} = 23.04
messageArr{end+1} = 23.04
messageArr{end+1} = 23.04
messageArr{end+1} = 23.04
messageArr{end+1} = 23.04
messageArr{end+1} = 23.04
messageArr2 = [];
messageArr2{end+1} = 17.01
messageArr2{end+1} = 17.02
messageArr2{end+1} = 17.03
messageArr2{end+1} = 17.04
messageArr2{end+1} = 17.04
messageArr2{end+1} = 17.04
messageArr2{end+1} = 17.04
messageArr2{end+1} = 17.04
messageArr2{end+1} = 17.04
messageArr2{end+1} = 17.04
messageArr2{end+1} = 17.04
messageArr2{end+1} = 17.04
messageArr2{end+1} = 17.04
messageArr2 = messageArr2.'%'//
Y = horzcat(messageArr, messageArr2)
Y = cell2mat(Y)
```

It gave me a 13x2 double matrix:

```23,0100000000000    17,0100000000000
23,0200000000000    17,0200000000000
23,0300000000000    17,0300000000000
23,0400000000000    17,0400000000000
23,0400000000000    17,0400000000000
23,0400000000000    17,0400000000000
23,0400000000000    17,0400000000000
23,0400000000000    17,0400000000000
23,0400000000000    17,0400000000000
23,0400000000000    17,0400000000000
23,0400000000000    17,0400000000000
23,0400000000000    17,0400000000000
23,0400000000000    17,0400000000000
```

But I think this is not the right way to do it. I need a more simple way to just append, and remove the first row without the necessity of concate cells and doing transpose of cells.

## Answers

This code will append a new row and remove the first row:

```% create five rows of two-column data
d=[22.3 18.3; 22.4 18.4; 22.5 18.3; 22.4 18.3; 22.2 18.6]
% this is a new row of data
newrow = [22.8 17.1]
% drop the first row and append the new data at the end
d = [d(2:end,:); newrow]
```

It uses the [ ] concatentation operator.

### Session Variable No Longer Working

I wonder whether someone may be able to help me please.

### how to take the year using date stored in DataBase:

how to take the year using date stored in DataBase: