Effacer les filtres
Effacer les filtres

Average a cell with ignoring NaN

6 vues (au cours des 30 derniers jours)
Ahmad Bayhaqi
Ahmad Bayhaqi le 29 Avr 2021
Commenté : Jan le 30 Avr 2021
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 commentaire
Jan
Jan le 29 Avr 2021
Please post an example for your inputs.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 29 Avr 2021
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 commentaires
Ahmad Bayhaqi
Ahmad Bayhaqi le 29 Avr 2021
Hi @Jan, yes it works.
Thank you very much
Jan
Jan le 30 Avr 2021
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by