Senyokbalgul
Senyokbalgul

Reputation: 1102

How to find if any array elements are larger than a certain value using `arrayfun`

Let's say we have an array numbers. If any elements in the array are greater than 3, I want to make array equal nan.

array = [1 2 3 4 5];

if arrayfun(@greater than 3,array)
    array = nan;
end

Upvotes: 0

Views: 241

Answers (1)

Mingjing Zhang
Mingjing Zhang

Reputation: 943

You don't really need arrayfun for this simple job. if any(array > 3); array = nan; end is all you need.

Upvotes: 2

Related Questions