Append elements to matrix in Matlab -


i want make matrix 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 case have 5 rows 2 columns

but need append new row dynamically, removing first based in given window want.

e.g. have window of n elements in row, when append new row in matrix, must remove first one.

in above example, window of 5 rows: if need input (append) new row: 22.8 17.1 row become 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 6 rows, need remove first one. after row becomes (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 append new row in matlab? - how remove new row in matlab?

i saw in matlab it's possible handle matrix vectors , cells.

e.g achieved 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 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 think not right way it. need more simple way append, , remove first row without necessity of concate cells , doing transpose of cells.

this code append new row , remove first row:

% create 5 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] % new row of data newrow = [22.8 17.1] % drop first row , append new data @ end d = [d(2:end,:); newrow] 

it uses [ ] concatentation operator.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -