# MATLAB: How not to overwrite the values of a variable

overwrite variable

my code is resolving an algebraic-differential system of equations. thus, it is built as the main file (main), that is calling another file (sis_dif), where there are the differential equations and that is calling anothere file (sis_alg), where there are the algebric equations. my problem is that when I call in the main the value of a variable that is calculated in the sis_dif file it gives me only the last value because it overwrites its value at each step of integration. i am looking for a way to tell to Matlab not to overwrite this value, but to create, for example an empty vector at the beginning and to fill it with each value given by the resolution of both the file which form my algebraic-differential system. basically, in the main i call the differential system:
``    [t,y] = ode45(@Sisdif, tspan, y0, options);``
and the system is 4 equations like dy/dt, where y are the differential variables. in these equations compare the algebric variables, so in the code Sisdif i call the algebric system:
[sol,exitflag] = fsolve('sisalg',v,options);
and the system is 2 non linear agebric equations. and one of these two "sol" is the solution i am looking for and i need to plot its value with the time in the main file. Thus, i put it in the global variables in order to have it in the main file, but it only gives me the last value since it is calculated in the algebraic system and not in the differential. i hope that is clear this time.

``for k = 1:n  result = YourOperations;end``
``result = zeros(1, n);for k = 1:n  result(k) = YourOperations;end``