The Code to replace non-threshold indexes in Array
조회 수: 10 (최근 30일)
이전 댓글 표시
Hello,
A = randi(5,5);
idx = find(A > 3);
A(idx) = log10(A(idx));
After running the above lines of code, what's the easiest(fastest) way to replace the non idx index in A with a certain value(100 for example)?
A(~idx) = 100; doesn't work the way I intended to.
Thanks!
댓글 수: 0
채택된 답변
Steven Lord
2024년 10월 14일
Get rid of the find call.
A = randi(5,5)
idx = (A > 3) % Make a logical mask
A(idx) = log10(A(idx)) % Use the logical mask to identify locations to change
A(~idx) = 100 % Use the negation of the logical mask to identify locations to change
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!