I am testing a vector to see whether it contains any NaNs. If it does, then I don’t want my action to be performed. If it contains no NaNs, the action should be performed. At present, my code looks like this (and it works):
if find(isnan(myVector))
else
action;
end
Since there is nothing in the if section, having my action under the else clause seems sloppy. How do I go about rephrasing the block so that I don’t need to use the else?
I have already tried the following:
if ~find(isnan(myVector))
if find(~isnan(myVector))
if find(isfinite(myVector))
To clarify, my input vector could contain any number of NaNs, but I only want ‘action;’ to execute if there are none at all.
1 Answer