simple matrix process for some values
1 view (last 30 days)
Show older comments
Kamyar Mazarei
on 8 Apr 2021
Answered: Star Strider
on 8 Apr 2021
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
0 Comments
Accepted Answer
Star Strider
on 8 Apr 2021
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
0 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!