Find indices in 2D Matrix
조회 수: 38 (최근 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!