Your u is a vector. The condition will be considered true only if all the entries are true, which is to say the same as if
and conversely it will fail if even a single value happens to be exactly 0.
This seems to be unlikely to be what you want.
If you are still dealing with the buffer initialization problem that I discussed with you before, you probably want
You have the same issue that u is a vector so the condition is only true if all of the values are equal to 1/true
Why the heck are you dividing 1 by true ?? The result is the same as 1 (double precision) . And you do not need to compare to anything as isnan() is already true or false. Your line is the same as
which in turn as discussed is the same as
Then you have
Remember that size() with a single argument always returns a vector with at least two elements. For example if u is a row vector of length 7, size(u) would return the vector [1 7] . And you are then using that vector of values as linear indices. If u does happen to be a vector, the result will be the same as if you had set locs(1) and locs(numel(u)) to 0... but they are already 0 because of the way you initialized them.
Then you have your else, which does the same thing as your elseif . Why bother to have the elseif if you are not going to do something different?
You are no testing for the possibility that u is empty or has only one element.