Borrar filtros
Borrar filtros

Question with a row matrix (simple)

2 visualizaciones (últimos 30 días)
Mate 2u
Mate 2u el 15 de Jun. de 2012
Hi there, I have a matrix of size 500000 x 1. I want to minus 0.00006 from each element which is not zero. If there is a zero then it would not minus from 0.

Respuesta aceptada

Wayne King
Wayne King el 15 de Jun. de 2012
You probably want to use some tolerance from zero
x = randn(500000,1);
indices = find(abs(x-0)<eps);
x(indices) = x(indices) - 0.00006;
The tolerance is assuming that you have a vector of floating point numbers here. I've used eps with no argument, it may be better here to use eps(0), which is a smaller number, than eps, but it's hard to say not knowing your application. It may be sufficient for you to just use some small number bigger than eps like 1e-6 for example.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by