I have a matrix that will be different depending on the data set I'm working with. It will always have a few columns where the first column is a reference column which starts are some arbitrary (but meaningful) value and increases by 1 for each row. The set of data will almost always be missing values and I can find the location of these missing points by building a perfect reference column and comparing it to the original data set (see below).
ref = [data(1):data(end)]' %rebuilding the reference column which will be equal to or larger than the original data set.
gaps = find(~ismember(ref, data(:,1))) %locates missing values in the original data set, based on the reference column.
From here I am trying to find an elegant solution to filling in the missing data by inserting rows. I've looked at close to 15 solutions so far and none really work for what I am trying to do. Hope someone can help before I finish option 2 (which sounds like a lot of work to me).
Option 1: I'm hoping there is an easy way to insert the missing reference values and NaNs into the desired matrix rows, before use fillmissing() to finish the job, but I don't know if this is even possible.
Options 2: Split the matrix at an identified gap, build a new matrix by appending a bottom row to the top half of the original matrix, and then using vertcat() to rebuild the matrix. Repeat for each instance until no gaps are identified. I guess this would need a while loop.
I am using R2017a.
Best Answer