Edit:
matrix multiplication can be faster than the sum, so the operation is almost twice as fast for matrices above 500 x500 elements (on my Matlab 2012a machine). So my solution is:
find(~isnan(data*zeros(size(data,2),1)))
Of the two methods you proposed (indicated by fand g) in the question, the first is faster (using timeit):
data=rand(4000);
nani=randi(numel(data),1,500);
data(nani)=NaN;
f= @() find(~isnan(sum(data, 2)));
g= @() find(all(~isnan(data), 2));
h= @() find(~isnan(data*zeros(size(data,2),1)));
timeit(f)
ans =
0.0263
timeit(g)
ans =
0.1489
timeit(h)
ans =
0.0146
source
share