MOVENAN (v1.0, mar 2011)
MOVENAN - Move NaNs to the beginning or the end of a column
For vectors, MOVENAN(V,1) moves the NaNs in V to the end. MOVENAN(V,-1)
moves them to the beginning. For 2D matrices, MOVENAN(M,1/-1) moves the
NaNs in each column of X to the end (1) or the beginning (-1).
MOVENAN(X) is the same as MOVENAN(X,1). The order of the non-NaN
elements in the input is unchanged.
[Y, XI, YJ] = MOVENAN(..) returns indices XI and YJ that can be used to
transform Y into X. For vectors, Y = X(XI) and X = Y(YJ). For matrices,
XI and YJ specify row indices, so that "Y(:,k)=X(XI(:,k),k)" and
"Y(YJ(:,k),k)=X(:,k)", for column k.
Examples:
X = [ 7 4 NaN 4 ;
NaN 3 NaN 3 ;
9 NaN 4 1 ;
10 11 NaN -1 ]
[Y, xi, yj] = movenan(X)
% Y= 7 4 4 4
% 9 3 NaN 3
% 10 11 NaN 1
% NaN NaN NaN -1
% show the relationsship between X and Y according to i and j:
c=2 ; [ Y(:,c) X(xi(:,c),c) ]
c=1 ; [ Y(yj(:,c),c) X(:,c) ]
% using transpose operations we can move along rows:
Y = movenan(X.', -1).'
% NaN 7 4 4
% NaN NaN 3 3
% NaN 9 4 1
% NaN 10 11 -1
See also sort, isnan, nanmean
Inspired by a post on CSSM (http://www.mathworks.com/matlabcentral/newsreader/view_thread/303636). I do not directly see a practical use for it, but, at least in my opinion, it may have an educational value.
引用格式
Jos (10584) (2025). MOVENAN (v1.0, mar 2011) (https://ww2.mathworks.cn/matlabcentral/fileexchange/30584-movenan-v1-0-mar-2011), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
平台兼容性
Windows macOS Linux类别
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!版本 | 已发布 | 发行说明 | |
---|---|---|---|
1.0.0.0 |