# Thread: Referencing matrix cells in matlab

1. ## Referencing matrix cells in matlab

Hello, im having trouble with this matrix (shown below). What im trying to do is make a row vector of all the values along the row number defined by j, except for the main diagonal. So that in effect, each value is taken as it is shown in the matrix, apart from the diagonal values.

M = [2 -1 -0.5 0 0 0 0 0;-1 4 -1 0 0 0 0 0; -0.5 0 2 -1 -0.5 0 0 0; 0 -1 -1 4 0 -1 0 0; 0 0 -0.5 0 2 -1 -0.5 0; 0 0 0 -1 -1 4 0 -1; 0 0 0 0 -1 0 3 -1; 0 0 0 0 0 -1 -0.5 3]

for j=1:L
M(j,1:L)
end
in effect what im am trying to command is
M(j,1: (j-1) && (j+1):L)
so that it misses out the j column.
where L is defined as the length of the matrix

Any help would be fantastic

2. Originally Posted by p123nky
Hello, im having trouble with this matrix (shown below). What im trying to do is make a row vector of all the values along the row number defined by j, except for the main diagonal. So that in effect, each value is taken as it is shown in the matrix, apart from the diagonal values.

in effect what im am trying to command is

so that it misses out the j column.
where L is defined as the length of the matrix

Any help would be fantastic
[M(j,1:j-1),M(j,j+1:L)]

CB