simple matrix process for some values

1 回表示 (過去 30 日間)
Kamyar Mazarei
Kamyar Mazarei 2021 年 4 月 8 日
回答済み: Star Strider 2021 年 4 月 8 日
hi im new to matlab
i want to process some of the matrix values but not all
like if i have a matrix i just want to add 10 to any value thats less than 5
its just an example can you help me with basic commands on this?
thank you

採用された回答

Star Strider
Star Strider 2021 年 4 月 8 日
Use ‘logical indexing’:
M = randi(10,6)
Mnew = M+(M<5)*10
producing (in this random instance):
M =
8 6 5 2 1 2
9 4 10 6 3 1
2 2 2 3 1 4
2 3 8 2 5 5
4 10 8 3 1 2
1 7 6 9 9 10
Mnew =
8 6 5 12 11 12
9 14 10 6 13 11
12 12 12 13 11 14
12 13 8 12 5 5
14 10 8 13 11 12
11 7 6 9 9 10
See the documentation section on Matrix Indexing for details.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by