MATLAB: I want to save values from the if statement in an array

arrayconditionstatementloopsavedatavalues

I am trying to save values of the peakInterval which lies in between 550 and 900 to a separate array. I don't know why this code doesn't save the values in the x array. Can you fix the problem?
x=[]
if (peakInterval >= 550) & (peakInterval<=900)
x=peakInterval
end
x(:)=[]

Best Answer

mask = (peakInterval >= 550) & (peakInterval<=900);
x = peakInterval(mask);