I need to insert NaNs into in specific positions of an array.
I wrote the code that is correctly doing it, but as I need to do it for really large arrays, it's taking too long to run. Numpy has the function insert(i, x) that inserts an item at a given position. Is there a similar function in Matlab? Or is there a more efficient way to do it?
a = [1 2 3 5 6 7 9 10 13 14];
insertNanIndex = [0 1 0 1 1 0 0 0 1 1 0 0 1 0 0 0];
for i = find(insertNanIndex)
a = [a(1:i-1), NaN, a(i:end)]
end