How to take an average of row elements in a two-column matrix when both elements do not contain a NaN, but use only the non-NaN value when there is a NaN?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Srh Fwl
le 26 Août 2020
Réponse apportée : Bruno Luong
le 26 Août 2020
I have a matrix with two columns of data. The data are measurements collected at the same times from different sensors, TT1 and TT2. I want to take an average of each row. My problem is dealing with NaN values. The column of data from sensor TDT2 contains many NaNs.
I know that I can use "nanmean" to ignore the rows where Column TDT2 contains a NaN. However, what I want to do is use only data from sensor TT1 (column 1) when there is a NaN from sensor 2 (column 2). In other words, I want to ignore the existence of column 2 when it contains a NaN.
Unfortunately, I can't figure out how to do this. If anyone has any suggestions, I would be very grateful. Thank you.
Here is an example (below) of a starting matrix and what I would want to end up with as a result:
2 2 --> 2
4 NaN 4
9 1 5
0 commentaires
Réponse acceptée
Bruno Luong
le 26 Août 2020
>> A=[2 2; 4 NaN; 9 1]
A =
2 2
4 NaN
9 1
>> mean(A,2,'omitnan')
ans =
2
4
5
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Computational Geometry 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!