Changing some elements of a matrix.

I have a matrix, which looks like 150 110 95 110 200 and so on. Now, i want to replace all elements up 95 (or less than 100) to 100, so that my new matrix should look like 100 100 100 110 200 Can anyone suggest me a good way to do this? Thanks.

 採用された回答

Joseph Cheng
Joseph Cheng 2014 年 4 月 9 日
編集済み: Joseph Cheng 2014 年 4 月 9 日

0 投票

I do not understand what you want to replace but if you know the inequality statement (A<B) you can do something like this
MATRIX(MATRIX<100) = 100; which will set all elements within your matrix which is less than 100 to 100.
or if there are two inequalities to satisfy.
MATRIX(MATRIX<100 & MATRIX>95) = 100; Set all elements in MATRIX which are between 95 and 100 to 100.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by