Question regarding matrix with NaN.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Sebastian Daneli
le 4 Avr 2022
Réponse apportée : Stephen23
le 4 Avr 2022
I have the following matrix:
X=[9 6 9; 0 2 nan; 3 1 2]
and from this one, I would like the following matrix
new=[3 3 3 2 2 3 3 3; 9 6 9 0 2 3 1 2]
i.e., a new matrix with the number of entries at any given row in matrix X, and a new row omitting the NaN in X.
0 commentaires
Réponse acceptée
David Hill
le 4 Avr 2022
s=sum(~isnan(X),2);
a=X';
newX=[repelem(s',s');a(~isnan(a))'];
0 commentaires
Plus de réponses (1)
Stephen23
le 4 Avr 2022
X = [9,6,9;0,2,nan;3,1,2]
tmp = X.';
idx = ~isnan(tmp);
cnt = sum(idx,1);
M = [repelem(cnt,cnt);tmp(idx).']
0 commentaires
Voir également
Catégories
En savoir plus sur Linear Algebra 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!