simple matrix process for some values

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by