How to add extra columns at specified locations
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
GMabilleau
am 1 Feb. 2024
Bearbeitet: Bruno Luong
am 1 Feb. 2024
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 Kommentare
Akzeptierte Antwort
Bruno Luong
am 1 Feb. 2024
Bearbeitet: Bruno Luong
am 1 Feb. 2024
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Preprocessing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!