MATLAB: Error in a ODE in a loop (returns a vector of length 9, but the length of initial conditions vector is 2)

for loopfunctionlooploopsMATLABmatlab functionode

Hi everybody, and thanks again for the help.
I run the file ciclo_1_bis, which loads from the file z_matlab_1 different vectors, and at every loop
it updates the initial condition, and other parameters stored in z_general_1.
First loop (j=1) ok, the when j=2 it says this erroor message:
Error using odearguments (line 92)
GREITZER returns a vector of length 9, but the length of initial conditions vector is 2. The vector returned by
GREITZER and the initial conditions vector must have the same number of elements.
Error in ode113 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
what could be possibily wrong? It just changes the initial conditions and the time for the next loop.

Best Answer

When you
save main_parameters.mat
after the first loop, then the workspace includes the t that was the result of the [t,y] = ode113() call.
When you load() that .mat inside the function, that t gets pulled inside the workspace, replacing the t that was passed in as a function parameter.
Don't DO that. Do not save() and load() like that. Pass the values in to the function, either individually or as part of a structure. http://www.mathworks.com/help/matlab/math/parameterizing-functions.html