MATLAB: Finding elements in array

arrayfindingfor loopstruct

I have an array
vk = [0 0.025 0.05 0.075 0.1 0.125 0.15 0.175].
I am writing this line
op= vk(vk>= 0.05 & vk<= 0.175)
The result which I am getting is
op =
0.0750 0.1000 0.1250 0.1500 0.1750
which is wrong, I should get
0.05 0.0750 0.1000 0.1250 0.1500 0.1750
does anyone know what I am doing wrong?
Also how I can get the indices number of the array vk and of op?

Best Answer

To get the indices to the vk array
vk = [0 0.025 0.05 0.075 0.1 0.125 0.15 0.175];
[idx] = find(vk>= 0.05 & vk<= 0.175);
op = vk(idx)