indexing a matrix with another matrix

Let's say I have a matrix A (Nx2) which holds pixel indices of pixels in matrix B. I would like to use matrix A and replace the pixels in matrix B with some value (e.g.255) the easy way would be to use a For loop: B(A(i, 1), A(i, 2)) = 255; Is it possible to do this without a loop?
Best regards Avner Mediouni R&D Physicist

Answers (1)

B(sub2ind(size(B), A(:, 1), A(:, 2))) = 255;

Asked:

on 18 Jan 2017

Answered:

on 18 Jan 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!