I have two arrays x and y of size 4013. The values of x array are row indices and of y array are column indices. I want to create a matrix of size 512*512 and insert values using x and y indices. How can I do this ?
1 Answer
You can use sub2ind to turn index vectors into matrix indices. For example:
x = randi(512, 4000, 1);
y = randi(512, 4000, 1);
val = 255;
mat = zeros(512, 512);
mat(sub2ind(size(mat), y, x)) = val;
xandywould act as the indices, but what values would you put in there in the matrix and what about the indices of the matrix that won't be indexed with them?val=255;