LSQNONLIN is using the values in the Fopt vector to determine the gradient, and it does this by calculating Fopt at different points. For example, it might take the difference of entry 10 from iteration 1 and entry 10 from iteration 2 and then use that to determine which way is downhill.
So you don't want to change the position of the values that the function is returning, as this could mess up the gradient calculation.
If LSQNONLIN encounters a NaN in Fopt, it is treated similarly to an Inf. Since we're trying to minimize, this point will most likely get rejected and LSQNONLIN will try to move back to a solution space where all of the values in Fopt were finite.
So the questions you need to ask yourself is: How do I want NaN's in Fopt to be interpreted? If having NaN's in Fopt is a bad solution for your problem, then it's fine for the Fopt vector to return NaN's since LSQNONLIN will treat those as really bad values of your objective function. If NaN has some other meaning, you may need to change your objective function to quantify what it means to have a NaN (i.e. if NaN is a good thing, then you would want to replace the NaN's in Fopt with something with a low penalty value).