Find indices in 2D Matrix
23 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I'm trying to solve he problem with my indices. I have a 2D matrix A with ones and zeros. Now i want to define my other matrix B on those coordinates where A=1. But in the end i still want to have an 2D Matrix, not a vector with indeces.
Does anyone know how this could be solved.
Thank you!
A = rand(50,20)>.3;
B=rand(50,20);
newmatrix=B(A);
0 个评论
采纳的回答
the cyclist
2021-7-29
Is this what you mean? (I made the matrices smaller, just to show the result.)
A = rand(5,2)>.3;
B = rand(5,2);
newmatrix = zeros(size(A));
newmatrix(A) = B(A)
5 个评论
the cyclist
2021-7-30
编辑:the cyclist
2021-7-30
Ah, sorry. You must have an older version of MATLAB. Newer versions (since R2016b) have implicit expansion. Glad you found bsxfun.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!