I have a matrix say
Z = [1 2 3;
4 5 6;
7 8 9]
I have to change its values, say at positions (2,2) and (3,1), to some specified v
You would like to do this
z(rowNos, colNos)
but you can not - MATLAB does a Cartesian product of the indices. You can do this trick
idx=(colNos-1)*size(z, 1)+rowNos;
z(idx)=0
Flatten the z-matrix and access it through a linear index, which is a combination of rowNos and colNos. Remember that MATLAB flattens the matrix by columns (column-based matrix storage).