matrix index is out of range for deletion

S
Shanaya · Jul 17, 2020 · 2.1K views
Question
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.
Expert Answer
Profile picture of John Williams
John Williams PhD Expert
Answered Aug 11, 2026
 pitch(TF == 1) = []
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!