Replacing all values of a with b in a matrix?
3 ビュー (過去 30 日間)
古いコメントを表示
JARED VAHRENBERG
2020 年 10 月 29 日
コメント済み: JARED VAHRENBERG
2020 年 10 月 29 日
Say I define that a and b are 3 and 4, respectively. I heva a matrix M that I want to swap all instances of a with b. How would I do that? I tried doing
res = M(M==a) = b;
it works if I don't have the res there but I need the res there to output my result for this specific issue. It keeps telling me it needs to be
res = M(M==a) == b; but that only gives me the 2x1 logical array that has 0 0 in it
2 件のコメント
madhan ravi
2020 年 10 月 29 日
Show what’s M and how the resulting M should be with e a small example.
採用された回答
madhan ravi
2020 年 10 月 29 日
What do you expect == is a logical operator, when not used in symbolic calculations if you just want to assign it, then simply use
res = M;
res(res == a) = b
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!