Hi I am planning to automate this piece of code which is below:
A=[1 2 3 4 5 6 7 8 9 10]
len_A=length(A)=10
if (A(3)>A(2))
Num_mean= mean(A(1):A(3))
if (A(5)>A(4))
Num_mean= mean(A(3):A(5))
if (A(7)>A(6))
Num_mean= mean(A(5):A(7))
if (A(9)>A(8))
Num_mean= mean(A(7):A(9))
Num_mean= mean(A(9):A(10))
else
Num_mean= mean(A(7):A(8))
end
end
end
end
The length of A is always greater than 2 and it is always even.
Here is another example
A=[1 2 3 4 5 6]
len_A=length(A)=6
if (A(3)>A(2))
Num_mean= mean(A(1):A(3))
if (A(5)>A(4))
Num_mean= mean(A(3):A(5))
Num_mean= mean(A(5):A(6))
else
Num_mean= mean(A(3):A(4))
end
end
Any help in automating it for any numbers in array A and for any length? All the values should be stored in Num_mean