> A couple of questions/clarifications - First, why wouldn't the first result be: > [1;NaN;NaN;NaN;5;NaN;NaN;NaN;9] > Second, is your vector (matrix) ALWAYS of odd length? Even so, what if its something like: > [1;NaN;NaN;NaN;NaN;NaN;7] > what do you want on the second iteration of: > [1;NaN;NaN;4;NaN;NaN;7] > Do you want: > [1;2.5;2.5;4;5.5;5.5;7]> > or > [1;2;3;4;5;6;7]
I have no idea why I put 5.5 that first time around, it would indeed be 5.
The matrix should always divide evenly by twos between midpoints, so I suppose it would always be odd. The matrices will follow a 2x-1 pattern, so: 3, 5, 9, 17 length matrix.
I've figured out how to make it work in a clunky way with this 17 length matrix:
%Establish the original matrix POINTS = NaN (17,1); %Populate first and last values: POINTS(1) = 1; POINTS(end) = 17;
%4 iterations for a matrix of length 17 for h = 1:4 idxx = find(~isnan(POINTS(:))); %find the indexes of values cnt = 2; %start a counter for j = idxx(1:end-1)' %start from index of 1 to second to last index value
x = POINTS(j); %first point y = POINTS(idxx(cnt)); %second point m = mean([x y]); %mean
POINTS(mean([j idxx(cnt)])) = m; %location to put new value cnt = cnt+1; %increase count end end