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!