MATLAB: Matrix index is out of range for deletion

deletionforifMATLABmatrix

Hello, I am trying to delete certain rows of an 1D array if a conditional statement is true.
My code is:
for i = 1:length(TF)
if TF(i) == 1
pitch(i) = [];
end
end
for the length of TF (a logical array) i evaluate TF as true or false and if it is true i want to delete the value in the array called pitch at that corrasponding index.
I am getting an error message that says "Matrix index is out of range for deletion."
I cannot seem to fix this probem and would appreciuate any help or suggestions.
Thank you,
Adam

Best Answer

pitch(TF == 1) = []