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

 采纳的回答

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

更多回答(1 个)

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