MATLAB: Why doesn’t limitation this work

errorforloopmatrix

So I've got another loop which makes a new matrix called nn. The values in nn varies a lot. The only interesting interval is between 300 and 1300 so I made this loop to remove all values outside the interval.
for i=1:length(nn)
if nn(i) < 300 || nn(i) > 1300
nn(i) = [ ];
end
end
I get this message:
Index exceeds matrix dimensions.
Error in HRV (line 60)
if nn(i) < 300 || nn(i) > 1300
I don't know what the problem is. Please help

Best Answer

for i=length(nn):-1:1