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!!!

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 25 de Mzo. de 2013
Editada: Azzi Abdelmalek el 25 de Mzo. de 2013
EDIT
B=A
B(B>2.9 & B<3.2)=-1

2 comentarios

B(2.9<B & B<3.2) = -1;
rox
rox el 26 de Mzo. de 2013
thanks a lot! worked greatly :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

rox
el 25 de Mzo. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by