MATLAB Plotting Variables (b,u) in Function "Step"

AI Thread Summary
The discussion revolves around plotting variables (b, u) that are defined within the "step" function while using the ODE solver ode45 in MATLAB. The user is attempting to access these variables in the main function but encounters issues since they are not directly available. A suggestion is made to refer to the documentation for ode45, indicating that understanding the function's output and how to manage variable scopes in MATLAB is essential for resolving the problem. The focus is on ensuring that the user can effectively plot the desired variables by properly managing their definitions and accessibility within the code structure.
madjid222
Messages
4
Reaction score
0
Hi Friends
I want to plot variables (b,u) that are in function "step" .
function main
[t,v]=ode45('step',[0 20],0,[]);
plot(t,v)

function dv=step(t,v)
c1=1;
if t<10
u=1;
else
u=-1;
end
dv=c1*u-2*v;
b=dv/2;


but these variables are unknown in function "main".
thanks.
 
Physics news on Phys.org
please help me
 
This should solve your problem:

Code:
doc ode45
 

Similar threads

Replies
2
Views
2K
Replies
8
Views
2K
Replies
1
Views
2K
Replies
2
Views
3K
Replies
4
Views
1K
Back
Top