MATLAB: Fine the first index of the value that is greater than zero along specific dimension.

find function

Dear all, How can I find the first index of the value that is greater than zero along third dimension from a 4-D matrix without using looping. Any help would be appreciated.
Sincerely, Charles Tai

Best Answer

You do not need to subtract and check compared to 0.
idx3 = sum( cumprod(T <= 320, 3), 3) + 1;
The result over an AxBxCxD matrix will be AxBx1xD .
In cases where no entries were greater than 320, the entry will be size(T, 3) + 1