MATLAB: Mean command gives wrong answer

mean command gives wrong answer

Hi. I want to calculate the mean of a data and the mean command gives wrong result. Below is the code. I should get 160 but, the code gives 21. Can someone hlep me finding the miskate.
Thanks.
x=[1,2,3,4,5,6,7,8,9,10,11,12]; % x values
y=[15,120,2,30,40,150,60,170,80,9,15,1000]; % y values
idx1 = x > 3 & x < 10; % specific x values
idx = y(idx1) >= 150; % specific y values
a=mean(y(idx))

Best Answer

Analyze this
%%


x=[1,2,3,4,5,6,7,8,9,10,11,12]; % x values
y=[15,120,2,30,40,150,60,170,80,9,15,1000]; % y values
%%
idx1 = find( x > 3 & x < 10 ); % specific x values
idx = find( y(idx1) >= 150 ); % specific y values
%%
a = mean(y(idx1(idx)))
a =
160