MATLAB: Assigning matrix values using lists of 2-way coordinates

coordinatesmatrix

I have a set of 2-dimensional coordinates in [row, col]. I want to assign a value to a matrix for those coordinates. Say row=[5, 8, 3, 5] and col=[4, 8, 2, 5]. Then I want
matrix(5,4)=
matrix(8,8)=
matrix(3,2)=
matrix(5,5)=
and so on automatically.

Best Answer

If the matrix exists already,
matrix( sub2ind( size(matrix), row,col) ) = values