Replace certain values of matrix by one single value

Hi I'm relatively new to Matlab.. I would like to know how to generate a matrix B that replaces all components of a matrix A (which is a 100x100 randomly generated matrix) lying between 2.9 and 3.2, by -1. I also tried using the for loop but it wouldn't work.
for i=1:100;
j=1:100;
if A(i,j)==2.9:3.2;
A(i,j)=-1;
end
end
Thanks a lot!!!

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 25 日
編集済み: Azzi Abdelmalek 2013 年 3 月 25 日

2 投票

EDIT
B=A
B(B>2.9 & B<3.2)=-1

2 件のコメント

Walter Roberson
Walter Roberson 2013 年 3 月 25 日
B(2.9<B & B<3.2) = -1;
rox
rox 2013 年 3 月 26 日
thanks a lot! worked greatly :)

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by