Rounding-off zero to negative

Is there any built-in function in matlab that takes all the negative values equal to zero? or round off negative values to zero? Regards

 채택된 답변

Oleg Komarov
Oleg Komarov 2011년 8월 16일

0 개 추천

% Random input
A = randn(10,1);
% Index negative values
idx = A < 0;
% Substitute them with zero
A(idx) = 0;

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 8월 16일

2 개 추천

A = max(A,0);
But cross-check whether this gives you the behaviour you want for NaN.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by