I'm not sure if this can be vectorized ... a simpler solution would probably be a loop:
newRow = []; nans = isnan(A(:,1)); for ii = 1:size(A,1) if nans(ii) %# first row might be NaN -- skip it if ii==1 continue; end %# for all other rows: if isempty(newRow) newRow = A(ii-1,:); end A(ii,:) = newRow; else newRow = []; end end
source share