I want to write such a code for two matrixes:
x=[1 1 1 2 2 3 3 3 3]';
y=[11 21 31 24 32 33 13 37 3]';
How can I find out the mean value of each group of numbers in y, that have the same index in x?
My algorithm can look like:
If x(1)=x(2) counter1=1 sum1=y(1)+y(2)
x(2)=x(3) counter1=2 sum1=sum+y(3) Define newx1=x(1) newy1=sum1/counter1
x(3)<>x(4)
x(4)=x(5) counter2=1 sum2=y(4)+y(3) Define newx2=x(4) newy2=sum2/counter2
x(5)<>x(6)
x(6)=x(7) counter3=1 sum3=y(6)+y(7)
x(7)=x(8) counter3=2 sum3=sum+y(8)
x(8)=x(9) counter3=3 sum3=sum+y(9) Define newx1=x(6) newy3=sum3/counter3
My problem here is using more then two counters in a loop. Probably, I should write something like:
s=1:8
for k=1:9
if x(k)=x(k+s);
else
s=s+1;
end
end
which didn’t work:(
I’ll be greatfull for any help or advise!
If I understood you correctly, you want the mean of each group of numbers that have the same index in “x”. In that case…