MATLAB: How to use if with the value of the array is a string

arrayif statement

I want to check if the final value of the string is 'NaN'
parents=[2 3 1 NaN];
f = parents(size(parents,2));
if f == 'NaN'
check=0
else
check=1
end

Best Answer

  • Replace
    if f == 'NaN'
    by
    if isnan( f )