I am using [m, d] = nanmax (r_all); to get the maximum values and corresponding indices in matlab. There are several columns in r_all in which all the elements are nans. Unfortunately, nanmax returns '1' in indices for those columns that have all nans. However, there are actual indices that are value '1' so it creates confusion. How can I force matlab to return 'a' or 'b' as the output instead of returning 0' or '1'? Could you please suggest other solutions to this problem?