Average a cell with ignoring NaN

조회 수: 1 (최근 30일)
Ahmad Bayhaqi
Ahmad Bayhaqi 2021년 4월 29일
댓글: Jan 2021년 4월 30일
Hi all,
I want to average with ignoring the NaN. I used the script below:
Intens2 = cellfun(@(C) cellfun(@mean, C), new_table3.extData, 'uniform', 0)
and the and I do average to Intens2
Intens3=cellfun(@mean, Intens2);
Is there a way to average in Intens2 and Intens2 with ignoring NaN?
where I can put 'omitnan'?
Thank you very much,
  댓글 수: 1
Jan
Jan 2021년 4월 29일
Please post an example for your inputs.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2021년 4월 29일
C = {[1,2,4,6,NaN], [NaN, 2, 3, NaN]};
MC = cellfun(@(x) mean(x, 'omitnan'), C)
MC = 1×2
3.2500 2.5000
  댓글 수: 2
Ahmad Bayhaqi
Ahmad Bayhaqi 2021년 4월 29일
Hi @Jan, yes it works.
Thank you very much
Jan
Jan 2021년 4월 30일
You are welcome. There are 3 nested cellfun calls in your code. Usually loops are faster than the nice cellfun. I'd post a loop method, if it is clear, what exactly your inputs are.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by