PDA

View Full Version : If statement in Matlab involving time variable


Srodrigu
Feb20-11, 05:25 PM
Im Having trouble writing an if statement with the time variable of the ode45 function.
I don't know if i need to create a new variable, which is not what i want, but just to create and if statement with the t variable from ODEs.

Hope someone knows how to solve this problem

Thank you

bob1182006
Feb21-11, 05:02 PM
I'm not sure what your code looks like but going from the example from matlab:
[T,Y] = ode45(odefun,tspan,y0)

Then you want an if statement based on T? Then you probably need to have the if statement inside of a for loop to go through each value of T, like:

for i = 1:length(T)
if T(i) == value
statement
end
end