Inserting NaN in particular spots of my matrix, all while "preserving" or shifting all other numbers
14 次查看(过去 30 天)
显示 更早的评论
I want to insert NaN in particular spots of two different sized matrices, with the number I'm "replacing" being shifted "down". For example:
a = [1 5 NaN 4 NaN 10 3]
b = [6 1 0 3 5]
I want b to look like:
b = [6 1 NaN 0 NaN 3 5]
So essentially my NaNs are located in the same index as matrix 1, however, I want to preserve the numbers in b, by moving them down by one index in my new matrix.
Any tips?
0 个评论
采纳的回答
Alfonso Nieto-Castanon
2014-7-16
编辑:Alfonso Nieto-Castanon
2014-7-16
If I am interpreting correctly (not really sure if this is what you mean by "shifted down") this should do:
c = nan(size(a));
c(~isnan(a)) = b;
更多回答(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!