MATLAB: Let consider a matrix A= [ 2 4 8 6 7 8] and mean of 1&2 , 3&4, 6&8 elements could be farmed as second matrix like B= [(2+4)/2=3 (8+6)/2=7 (7+8)/2=7.5] i.e B= [3 7 7.5] now i need a final matrix like A=[2 3 4 8 7 6 7 7.5 8]

matrix manipulation

ie i am taking mean of first two values of A and put that mean value in between that first two values then i am taking 3&4 values from A taking mean and put that mean value in between 3&4 like wise i have to go for longer values of data. pl help me

Best Answer

A= [ 2 4 8 6 7 8] ;
A = reshape(A,2,[]) ;
B = [2 3 4 8 7 6 7 7.5 8];
avg = mean(A) ;
C = zeros(size(A,1)+1,size(A,2)) ;
C(2,:) = avg ;
C(1:2:end,:) = A ;
C = C(:)';