Variable ... is undefined on some execution paths
5 Ansichten (letzte 30 Tage)
Federico Avino am 30 Nov. 2020
I'm doing a project in Simulink/Simscape, and it contains a Matlab Function block, which contains the code that must be executed each cycle by the simulator. In this block i need to calculate the discrete derivative of temperature doing (T1-T1_prev)/dt, where T1 is one of the inputs of the block.
In theory, the problem of this methode is the definition of T1_prev at the time 0 of the simulation, so i did an
function y = TCU(u)
time = u(6);
if time <= 0
T1_prev = 0;
temperature_tank1 = temperatureCheck (T1, T1_prev, Tmax, Tsig, dT_dt_max, deltat);
T1_prev = T1;
I reported just the parts which i have problems with. In this way matlab says T1_prev is not fully defined due to the lack of an else case, but actually i don't want it, and T1_prev results fully defined, because it's updated in the end of the cycle for each cycle that is not the first. (T1 is updated each cycle too)
How can i solve the problem?
Thank you guys