matlab - Maltab, add vector to matrix -


i want add vector existing matrix. exampel:

matrix=[1 2 3         4 5 6         0 7 0]  vector = [7           8] 

so target find equal number of vector , matrix example with:

ismember(matrix,vector) 

after vector should insert matrix following:

matrix=[1 2 3         4 5 6         0 7 0         0 8 0] 

thanks everybody

instead of using ismember, can better use find 2 output arguments:

>> [row, col]=find(matrix==vector(1)) row =      3 col =      2 

using matlab's automatic matrix expansion, , assuming vector column vector (you can adjust code accordingly):

>> matrix(row:(row+length(vector)-1),col) = vector matrix =      1     2     3      4     5     6      0     7     0      0     8     0 

if match not @ edge (i.e., row~=size(matrix,1)), not work though, vector override other entries.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -