How to fill end of rows of a matrix with NaN values?
16 次查看(过去 30 天)
显示 更早的评论
I have a matrix M, and vector of indices K. I would like to make an element M(k,j) = NaN if j >= K(k). It is possible to do this with a vectorized short methode?
2 个评论
Bob Thompson
2021-6-1
编辑:Bob Thompson
2021-6-1
Why not just preallocate the matrix with nan values? Do you have any idea of the max size your matrix could be?
M = nan(max(k),max(j));
回答(2 个)
Walter Roberson
2021-6-2
M = [1,2,3; 1,2,3; 1,2,3; 1,2,3]
K = [2; 3; 1; NaN]
M((1:size(M,2)) >= K(:)) = nan
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!