I am struggling to write code to substitute particular values in a matrix.
I have a matrix, C, that contains multiple [r,c,v] values. I now want to use these co-ordinates to substitute values from matrix X with those from matrix Y- but only at the coordinates in matrix c. At the coordinates not in matrix c I would like to retain the values from matrix X.
As a simple example of what I am trying to do:
o1= [ 123 123 123; 123 255 123; 255 123 123];
o2= [ 4 4 4; 4 4 4; 4 4 4];
d1= [111 111 111; 111 255 111; 111 111 111];
d2= [5 5 5; 5 5 5; 5 5 5];
o_p= o1;
d_p= d1;
need to find coordinates in o_p and d_p where the values equal 255
[r,c,v] = find(o_p==255);
a= [r, c, v];
[r,c,v] = find(d_p==255);
b= [r, c, v];
c= [a; b];
Then I want to use the coordinates in c to replace the elements at these coordinates in both matrices with o2 and d2 respectively
Matrix C
map toMatrix X
andMatrix Y
? - Divakar