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.
horzcat
, why not tryvertcat
? I would start by putting together your full matrix, checking itssize
, and then delete the rows you don't want. – excazaY(rowIdx,:) = []
. Theend
keyword may also come in handy hereY = [Y(end-3:end,;) ; newRow]
will give you a moving window of size 5 – Some GuyBigMat = [BigMat ; NewRow]
You need to read a basic MATLAB tutorial. You can start here: mathworks.com/help/matlab/math/… – beaker