Rounding-off zero to negative
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Oleg Komarov
2011-8-16
% Random input
A = randn(10,1);
% Index negative values
idx = A < 0;
% Substitute them with zero
A(idx) = 0;
0 个评论
更多回答(1 个)
Walter Roberson
2011-8-16
A = max(A,0);
But cross-check whether this gives you the behaviour you want for NaN.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!