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
回答(1 个)
Guillaume
2017-1-18
B(sub2ind(size(B), A(:, 1), A(:, 2))) = 255;
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!