How do I debug my matlab code?
- Before trying to fix the problem see: Debug a MATLAB Program, then
- add a breakpoint to line 34, "bindata = data( ..."
- run the script, execution halts at line 34
- inspect the values of variables on line 34, data turns out to be empty, why is data empty?
- look for data in preceeding lines, data is assigned a value at line 24
- inspect (use the tooltip, hover over variables) the values of the variables on RHS in line 34 (shall be 24), ind2 is empty
- look for ind2 in preceeding lines, it's assigned in line 9
- in the command window run
No value of tim_trl is larger or equal to the value of t2
That's a copy&paste error (I think). The line should read
ind2 = find(tim_trl<=t2, 1);
That didn't solve the problem. No, it should read
ind2 = find(tim_trl<=t2, 1, 'last' );
And there are more problems.
Index in position 2 exceeds array bounds (must not exceed 1).
bindata = data(windowSt:windowEnd, channel);
At this point data is a column vector and channel has the value 2. Logical mistake, line 24 creates a column vector, channel is accounted for in line 24. Thus
bindata = data(windowSt:windowEnd);
Now the script runs without errors. Inspect the result. In the command window run