Declare global variable & share with other function, BUT global variable change every iteration
Mostra commenti meno recenti
I am trying to share the iteration result that changes every second for 2000 seconds period from a function to another function. I want to avoid getting additional variable back, so I declared the result global in both functions. The code looks like this:
global y
[t,x]=ode45('filename',[ODEstart:ODEspan:ODEend],init);
y=x(end);
in this case, x is an array of numbers, and I just want to pass the last value in the array into the other function, which looks like this:
function filename
global y
A=y^2;
B=....
end
The whole point of doing this is just to pass the value of y into filename.m. But sadly, the value of y wouldn't change (it should change after each iteration). So I'm stuck...
Is there any way to fix the error, or any other way to do this?
Please help me. Thank you.
Risposte (1)
Walter Roberson
il 17 Feb 2012
0 voti
What do you define as an "iteration" here? ode45() does not return any value until the entire time span is completed.
Have you considered using the options structure with an output function there?
1 Commento
Peiwen Lau
il 17 Feb 2012
Categorie
Scopri di più su Ordinary Differential Equations in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!