How to replace numbers in a matrix with another number?
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Omm Samantaray
el 13 de Jul. de 2022
Comentada: Voss
el 29 de Oct. de 2024 a las 17:33
I am stuck with a problem. I have a 2D matrix, let’s say, m*n as the size of the matrix. I want to put the values whose magnitude is less than a given constant (a very small decimal number) as 0, but I want to avoid for loop in my code for this.
Is there any way to do this?
Thank you.
Respuesta aceptada
Abhijit Nayak
el 13 de Jul. de 2022
I guess from my understanding of your question that you just want to replace the values with 0 if their magnitude is less than a number.
Try the given below code. It is better than having for loop for this operation in MATLAB.
A=rand(6,5)
n=0.5;
A(abs(A)<n)=0
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!