Three possible solutions:
1. If you have the Statistics Toolbox,
average_x = nanmean(x(:));
average_x = nanmean(x(:));
3. If you prefer to ignore the NaNs yourself,
average_x = mean(x(isfinite(x(:))));
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!