When I run your code, I don't get the error you cite on line 54. That seems to work fine. The only issue I found was when determining the sample number for the takeoff point.
It appears that you have one of the most common errors in software development. This is the copy/paste issue where you copy and paste a section of code that does almost what you need to do somewhere else but don't quite make all of the changes you need to make to do something slightly different.
Look at the while loop starting at line 62. Is it actually doing anything different on each pass through the loop? Will sampB4Takeoff change?
I suggest that you set a breakpoint at line 62 (see here for documentation on using the debugger: https://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html) and just step through the loop a few times and look at the value of the variables that you are using in the loop (you can just hover your mouse over a variable to see the value when stopped in the debugger). I think you will realize what you have done wrong and will be able to fix it.