How to increase value of some matrix numbers

1 回表示 (過去 30 日間)
Majid Mahmoodabadi
Majid Mahmoodabadi 2022 年 4 月 22 日
回答済み: David Hill 2022 年 4 月 22 日
Hi,
I have a matrix as following and want to increase the value of numbers (that are less than 9) by 1.
M= [12,16,3,5,1,11,13,22]
I applied the below logic:
M(M<9)= [B(i)+1]
This is what I got:
M =
12 16 17 17 17 11 13 22
But, I look for a response like this:
M =
12 16 4 6 2 11 13 22
I appreciate it if you could help me.

回答 (1 件)

David Hill
David Hill 2022 年 4 月 22 日
M= [12,16,3,5,1,11,13,22];
M(M<9)=M(M<9)+1;

カテゴリ

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