How to add extra columns at specified locations
3 次查看(过去 30 天)
显示 更早的评论
Hi!
I have a variable called "dataset" that corresponds to a vector containing numbers and nan values. Let say :
dataset = [1, 2, 3, nan, 4, 5, nan, 6, 7]
For the rest of the computation, i need to create a second vector, "dataset2", that lacks the nan values. Let say:
dataset2 = [1, 2, 3, nan, 4, 5, nan, 6, 7]
Some computation is done on dataset2. Let say "dataset2" is transformed into:
dataset2 = [2, 5, 7, 8, 4, 8, 10]. Now, I need to reconstruct a vector that is the same size as the "dataset" vector, and that contains the values of dataset2 after computation and also contains nan at their original location as:
dataset3 = [2, 5, 7, nan, 8, 4, nan, 8, 10]
I'm stuck to perform the last step. Any help would be appreciated.
Best,
Guillaume
0 个评论
采纳的回答
Bruno Luong
2024-2-1
编辑:Bruno Luong
2024-2-1
After computing dataset2
dataset = [1, 2, 3, nan, 4, 5, nan, 6, 7];
% ...
dataset2 = [2, 5, 7, 8, 4, 8, 10];
do this:
dataset3 = dataset;
dataset3(~isnan(dataset3)) = dataset2
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Preprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!