필터 지우기
필터 지우기

Question with a row matrix (simple)

조회 수: 2 (최근 30일)
Mate 2u
Mate 2u 2012년 6월 15일
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.

채택된 답변

Wayne King
Wayne King 2012년 6월 15일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by