Declare global variable & share with other function, BUT global variable change every iteration
显示 更早的评论
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.
回答(1 个)
Walter Roberson
2012-2-17
0 个投票
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?
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!