Question regarding matrix with NaN.
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
その他の回答 (1 件)
Stephen23
2022 年 4 月 4 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!