indexing a matrix with another matrix
Show older comments
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)
Guillaume
on 18 Jan 2017
B(sub2ind(size(B), A(:, 1), A(:, 2))) = 255;
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!