Logical Indexing Is Gold


Instead of looping with if-statements, use logical indexing:
A(A < 0) = 0;
One line, no loops, full clarity.
Stephen23
Stephen23 on 17 Nov 2025
For the given example MAX() will often be more efficient:
A = max(A,0);

Tags

No tags entered yet.