MATLAB: Retrieve original index from a masked array

arraysMATLAB

Hi, I am not sure if it is even possible, but suppose I have an array A and a mask m, and I use some function (e.g. min()) to find the index of an element in the masked function, is there a way to backtrack that element back to the original unmasked array?
In other words:
[~,i] = min(A(m)); % A is an array, m is a logical array mask
Now I want to find the index j such that A(j) is the same element as (A(m))(i)
Thanks,

Best Answer

Repalce the other elements in A with NaN other than mask.
B = A ;
B(~m) = NaN ;
[~,i] = min(B); % now the index will be of A