I have an array of values of the size (n,1,4), that contains Euclidian distances of vectors as well as some NaN values where the Euclidian distance is not applicable. An example of such a vector could be
E(:,:,1) = NaN 722.6494 948.3222E(:,:,2) = 286.7571 NaN 386.2155E(:,:,3) = NaN NaN 115.6732E(:,:,4) = 715.2429 227.8121 NaN
I want to set all but the minimum values along the 3:d dimension to NaN, but can't figure out how to use the indexing from min. I understand that
[~,I] = min(E,[],3)
Gives me the index value for each row, so in the above case I = [1, 4, 3].' – but how do I use this index in a meaningful sense to index the values I want to keep?
Best Answer