Declare global variable & share with other function, BUT global variable change every iteration
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Walter Roberson
on 17 Feb 2012
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?
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!