Hi Dun-Ren Liu
To accomplish your desired objective, you have the option to utilize the built-in “sub2ind” function available in MATLAB. Please refer to the sample code provided as an example.
f = zeros(5,5);
x = [1,2,3]';
y = [1,2,3]';
idx = sub2ind(size(f),x,y);
f(idx) = 1;
In this code snippet, “f” represents the matrix whose values you intend to modify, while “x” and “y” are vectors that store the row and column indices, respectively.