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!