Maith - if I run your code as a function (named g13.m) or as a script, I observe the following error
Index exceeds matrix dimensions.
Error in g13 (line 33)
x1 = [x(i:i+n3-n2) zeros(1,n3-n2)];
So we know the line, but not which iteration. To make the debugging easier, run the following command before running your above code
This will cause the debugger to pause at the line which generates the error, and you will be able to look at all variables at that point and so you can get an idea of what is happening. When I do this, I notice that this fails for when i is 17 (as an aside, you may want to use a different index variable name as i and j are also used to represent the imaginary number). The code then fails because of
as i is 17, n3 is 7, and n2 is 4 with x only being a vector with 18 elements. With that in mind, how would you modify this code to handle the case where i+n3-n2 exceeds 18?
Best Answer