How to replace the non zero values of a matrix with another value?
9 ビュー (過去 30 日間)
古いコメントを表示
How to replace the non zero values of a matrix with another value?
If there is a matrix 5*5 and it contains zero values, how can I keep the zero values and replace the non zero value with 0.1?
in matlab version R2018a
0 件のコメント
採用された回答
John D'Errico
2023 年 4 月 27 日
編集済み: John D'Errico
2023 年 4 月 27 日
A(A ~= 0) == 0.1;
One line of code. That applies to ANY release of MATLAB. As far back as I have been using MATLAB, so only back about 35 years or so.
And of course, there are other equally simple ways to solve it. For example:
A = (A ~= 0)*0.1;
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で NaNs についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!