Dear all,
I'm trying to calculate the max from a large multidimensional array where there are a lot of elements with -inf. Because the multidimensional array is large (around 100 million elements), I want matlab to ignore the -inf values when calculating the max. Another problem is the number of -inf can be different in each dimension, so I can't just trim the multidimensional array into a smaller one. Right now I think when I use max, the function is incorporating -inf in the calculation, which makes the computation slower.
To illustrate:
M=-inf*ones(1,3,1000000); M(1,1,1:2)=[1 .5]; M(1,2,1:2)=[2 1.5]; M(1,3,1:2)=[2.3 3]; tic max(M,[],3) toc N=ones(1,3,2); N(1,1,1:2)=[1 .5]; N(1,2,1:2)=[2 1.5]; N(1,3,1:2)=[2.3 3]; tic max(N,[],3) toc
ans =
1 2 3
Elapsed time is 0.009900 seconds.
ans =
1 2 3
Elapsed time is 0.004949 seconds.
My matlab version is R2013a. Thank you again for all your time!
Best Answer