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!