increment values which are larger than three

1 回表示 (過去 30 日間)
Sososasa
Sososasa 2014 年 4 月 2 日
コメント済み: Sososasa 2014 年 4 月 2 日
Hi,
If I have this matrix:
A=[ 2 1 3;
4 2 5;
1 1 6]
and I want to increment any value larger than three, so the resulting matrix look like this:
A=[2 1 3;
5 2 6;
1 1 7]
So here I increased 4,5,6 to be 5,6,7
Is there a nice way to use that without loop?

採用された回答

Mischa Kim
Mischa Kim 2014 年 4 月 2 日
Sososasa, use
B = A + (A>3)
  1 件のコメント
Sososasa
Sososasa 2014 年 4 月 2 日
great, thanks :)

サインインしてコメントする。

その他の回答 (2 件)

Carlos
Carlos 2014 年 4 月 2 日
編集済み: Carlos 2014 年 4 月 2 日
Try
A=[ 2 1 3;
4 2 5;
1 1 6]
a=find(A>3);
A(a)=A(a)+1
  1 件のコメント
Sososasa
Sososasa 2014 年 4 月 2 日
Thank you Carlos for your help

サインインしてコメントする。


Chandrasekhar
Chandrasekhar 2014 年 4 月 2 日
a = find(A>3);
A(a) = A(a)+1;
  1 件のコメント
Sososasa
Sososasa 2014 年 4 月 2 日
Thank you Akshata for your time :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by