MATLAB: Index in position 1 is invalid. Array indices must be positive integers or logical values.

indexing

I've attached my code below. I keep getting the issue of incorrect indexing but I'm not sure why this is as I have defined my for loop starting at 1. If someone could take a quick look and help me that would be great. I feel like I'm just overlooking something. The error occurs in line 36

Best Answer

Here is something fishy.
sigma = func2(t,x,sigma_x,func1(kc,t))
...
function sigma = func2(t,M,sigma_M,func1)
If you want to pass the output of func2 as an input to func1 that's ok, but do not name the output func1. This confusion causes func1 to be interpreted as a variable, which is why you get this error. You can pass the function as an argument like you do, but you need to name the variable used in func2 something other than func1.
What you do is similar to writing:
func1 = func1(arg1,arg2)
func1 is now a variable, so the next time you call it it will be interpreted as such.