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!