MATLAB If statement in Matlab involving time variable

Click For Summary
The discussion centers on difficulties in writing an if statement using the time variable from the ode45 function in MATLAB. The user seeks guidance on how to implement this without creating a new variable. It is suggested that to evaluate conditions based on the time variable T, the if statement should be placed inside a for loop that iterates through each value of T. This approach allows for checking specific conditions at each time step generated by the ode45 function.
Srodrigu
Messages
1
Reaction score
0
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
 
Physics news on Phys.org
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
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 3 ·
Replies
3
Views
1K